xf:DOMFocusIn won't work without an xf:dispatch to populate a dropdown on xf:DOMFocusIn alone.

I have the following code that uses xf:action ev:event="DOMFocusIn" in a select1 to populate the dropdown when the intent is to populate the dropdown without the use of a trigger and only when the select1 control is selected (by the DOMFocusIn (and not on an xforms:ready)

But I find that this does not happen if I do not place a xf:dispatch ev:event="xf:-model-construct" name="srcAttribute" inside an xforms:action element. (Do I need the xforms:dispatch at al).
The downside to placing the xforms:dispatch is that I end up populating the dropdown as soon as the XForm is loaded. If I do away with the xf:ready and the xf:dispatch and leave the DOMFocuIn in, the dropdown does not get populated at all.

In a situation where I have 15-20 dropdowns, I may not wish to have all my dropdowns populate on xf:ready, because of the 15-20 REST submission involved and all that server traffic.

So how do I address this situation: Is there a better way to use the xf:dispatch or is there something i am not doing something right about the xf:DOMFocusIn/

Here is the code:


<?xml version="1.0" encoding="UTF-8"?>
<xhtml:html xmlns:f="http://orbeon.org/oxf/xml/formatting" 
xmlns:ev="http://www.w3.org/2001/xml-events" 
xmlns:xf:="http://www.w3.org/2002/xf:" 
xmlns:xhtml="http://www.w3.org/1999/xhtml" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:fe="http://example.com/form/xform" xmlns:xxf:="http://orbeon.org/oxf/xml/xf:">
  <xhtml:head>
    
    <xf:model schema="form.xform.xsd">
      <!-- Task Input -->
      <xf:instance id="taskinput">
        <fe:input>
          <fe:Hair_Color_Dynamic/>
          <fe:Hair_Color_Dynamic_items>
            <fe:item>
              <fe:label>[dynamically]</fe:label>
              <fe:value>[dynamically]</fe:value>
            </fe:item>
          </fe:Hair_Color_Dynamic_items>
          
          <fe:physDescHair/>
          
          <fe:select13/>
        </fe:input>
      </xf:instance>
      <!-- Task metadata - used only for People Initiating Processes Task forms -->
      <xf:instance id="taskmetadata">
        <taskmetadata/>
      </xf:instance>
      <!-- Task Output -->
      <xf:instance id="taskoutput">
        <fe:output>
          <fe:Hair_Color_Dynamic/>
          <fe:physDescHair/>
          <fe:select13/>
        </fe:output>
      </xf:instance>
      
     		<xf:instance id="HairResponse">
					<hair>
						<item>
							 <ha_description/>
							 <ha_value/>
						</item>
					</hair>
				</xf:instance>
				
				<xf:submission
				id="sub-get-hair-data"
				action="http://localhost:9001/SimpleXmlServer/XmlIntercept/lists/HairPath"
				method="get"
				replace="instance"
				instance="HairResponse"/>
      
      <xf:action ev:event="xf:-ready">
        <xf:action xf:if="string(instance('taskoutput')/@saved) != 'true'">
          <xf:setvalue ref="instance('taskoutput')/fe:Hair_Color_Dynamic" value="instance('taskinput')/fe:Hair_Color_Dynamic"/>
          <xf:setvalue ref="instance('taskoutput')/fe:physDescHair" value="instance('taskinput')/fe:physDescHair"/>
          <xf:setvalue ref="instance('taskoutput')/fe:select13" value="instance('taskinput')/fe:select13"/>
        </xf:action>
      </xf:action>
      
      <xf:action ev:event="xf:-ready">
				<xf:action ev:event="DOMActivate">
					<xf:dispatch ev:event="xf:-model-construct" name="srcAttribute" target="HairResponse"/>
					<xf:send submission="sub-get-hair-data" />
				</xf:action>	
		</xf:action>
      
      
    </xf:model>
  </xhtml:head>
  <xhtml:body>
    <xhtml:div id="intalio-bpms-form">
      <xhtml:div id="xf:_cntrl_Hair_Color_Dynamic">
        <xf:select1 appearance="minimal" ref="instance('taskoutput')/fe:Hair_Color_Dynamic">
          <xf:label>Hair Color Dynamic</xf:label>
          <xf:itemset nodeset="instance('HairResponse')/item">
            <xf:label ref="ha_description"/>
            <xf:value ref="ha_value"/>
          </xf:itemset>
	          <xf:action ev:event="xf:-value-changed">
				  <xf:send submission="sub-get-hair-data"/>
			  </xf:action>
        </xf:select1>
      </xhtml:div>
      
      	<xf:select1 style="width:150px;border: 3px ridge #643;padding: 2px;" appearance="minimal" ref="instance('taskoutput')/fe:physDescHair">
				<xf:label style="padding-top: 9px;">HAIR COLOR CODE DYNAMICALLY PULLED IN:</xf:label>
					<xf:hint></xf:hint>
					<xf:help></xf:help>
					<xf:alert></xf:alert>
				<xf:itemset nodeset="instance('HairResponse')/item">
					<xf:label ref="ha_description" />
					<xf:value ref="ha_value" />
				</xf:itemset>
				<xf:action ev:event="DOMFocusIn" if="instance('HairResponse')/item">
					<xf:message level="modal"></xf:message>
				</xf:action>
				<xf:action ev:event="xf:-value-changed">
						<xf:send submission="sub-get-hair-data"/>
				</xf:action>
			</xf:select1>
      
    </xhtml:div>
  </xhtml:body>
</xhtml:html>

thanks for your time. - I

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

DOMFocusIn does work for xf:seelct1

Here is a working (tested with latest formsPlayer release) example that shows an xf:select1 control executing a submission (load a local file) via the DOMFocusIn event.

Local file inst-options.xml (place in same directory as the form below)

<?xml version="1.0" encoding="UTF-8"?>
<root>
	<opt label="Option 1">First option value</opt>
	<opt label="Option 2">Second option value</opt>
	<opt label="Option 3">Third option value</opt>
</root>

The form

<html 
	xmlns="http://www.w3.org/1999/xhtml" 
	xmlns:xf="http://www.w3.org/2002/xforms"
	xmlns:ev="http://www.w3.org/2001/xml-events" 
	xmlns:fp="urn:formsplayer.com"
>
	<head>
		<object id="formsPlayer" classid="CLSID:4D0ABA11-C5F0-4478-991A-375C4B648F58">
			<strong>formsPlayer has not loaded. Please check your installation.</strong>
		</object>
		<?import namespace="xf" implementation="#formsPlayer" ?>
		
		<style type="text/css">
			xf\:output,
			xf\:select1
			{
				display				: block;
				margin-bottom		: 10px;
			}
		</style>
		
		<xf:model id="mdl-x" functions="fp:HTMLSerialise">
			<xf:instance id="inst-options">
				<root xmlns="" />	
			</xf:instance>
			
			<xf:instance id="inst-selected-value">
				<value xmlns="" />
			</xf:instance>
			
			<xf:submission 
				id="sub-get-local"
				method="get"
				action="inst-options.xml"
				replace="instance"
				instance="inst-options"
			/>
			
			<xf:action ev:event="xforms-submit-error" ev:observer="sub-get-local">
				<xf:message level="modeless">
					<h3 style="color:red;">xforms-submit-error for sub-get-local</h3>
				</xf:message>
			</xf:action>
			
			<xf:action ev:event="xforms-submit-done" ev:observer="sub-get-local">
				<xf:message level="modeless">
					<h3 style="color:green;">xforms-submit-done for sub-get-local</h3>
				</xf:message>
			</xf:action>
		</xf:model>
	</head>
	<body>
		<xf:select1 ref="instance('inst-selected-value')">
			<xf:label>Choose something</xf:label>
			<xf:itemset nodeset="instance('inst-options')/opt">
				<xf:label ref="@label" />
				<xf:value ref="." />
			</xf:itemset>
			<xf:action ev:event="DOMFocusIn" if="not(instance('inst-options')/opt)">
				<!-- xf:message level="modeless">
					No xf:itemset data currently exists, will attempt to load from file
					</xf:message -->
				<xf:send submission="sub-get-local" />
			</xf:action>
			<xf:action ev:event="xforms-value-changed" if="instance('inst-options')/opt">
				<xf:message level="modeless">
					xf:itemset data exists, changed value
				</xf:message>
			</xf:action>
		</xf:select1>
		
		<xf:output value="fp:HTMLSerialise(instance('inst-options'))">
			<xf:label>inst-options</xf:label>
		</xf:output>
		
		<xf:output value="fp:HTMLSerialise(instance('inst-selected-value'))">
			<xf:label>inst-selected-value</xf:label>
		</xf:output>
	</body>
</html>

DOMFocusIN works!

Thanks a lot. It does work.
ilango

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.