Re: Allow xf:setfocus with no @control to set the focus to the event target

FWIW, in our implementation, all events have some context information.  
In particular, the event target is available. So we can write:

   <xf:setfocus control="event('xxf:target')"/>

(Where "xxf" is a prefix mapped to our extension URI.)

If the "target" context info was standardized in XForms, the syntax  
would be a bit cleaner as we wouldn't need the namespace:

   <xf:setfocus control="event('target')"/>

Now event('xxf:target') returns the target id. If the control doesn't  
have an explicit id set by the author, then one is automatically  
assigned at runtime. While this works for us, to be fair I am not sure  
the approach of producing ids for all event targets is acceptable in  
other implementations.

Still, what I like with the above approach is that the syntax leaves  
no doubt as to where the control onto which to set the focus comes from.

Just food for thoughts.

-Erik

On Aug 8, 2008, at 4:58 AM, Mark Birbeck wrote:

>
> Hello all,
>
> I was just looking something up in the spec, and noticed that if
> @control is omitted from the use of xf:setfocus then nothing happens.
>
> It occurred to me that omitting @control and defaulting to the event
> target might actually be a useful pattern.
>
> This example is a little contrived, because I've only just thought of
> the whole thing, but bear with me....
>
> Ordinarily, setting focus on a control when it is invalid could be
> done like this:
>
>  <xf:input id="me" ref="x">
>    <xf:label>X:</xf:label>
>    <xf:setfocus control="me" ev:event="xforms-invalid" />
>  </xf:input>
>
> But that requires naming the control with an @id, and then ensuring
> that the @control value and the control name are in sync. An easier
> and more maintainable way would be:
>
>  <xf:input ref="x">
>    <xf:label>X:</xf:label>
>    <xf:setfocus ev:event="xforms-invalid" />
>  </xf:input>
>
> If people don't like simply omitting @control, an alternative would  
> be:
>
>  <xf:input ref="x">
>    <xf:label>X:</xf:label>
>    <xf:setfocus control="" ev:event="xforms-invalid" />
>  </xf:input>
>
> Regards,
>
> Mark
>
> -- 
> Mark Birbeck, webBackplane
>
> mark.birbeck@webBackplane.com
>
> http://webBackplane.com/mark-birbeck
>
> webBackplane is a trading name of Backplane Ltd. (company number
> 05972288, registered office: 2nd Floor, 69/85 Tabernacle Street,
> London, EC2A 4RR)
>

--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/

Received on Friday, 8 August 2008 15:13:58 UTC