Re: Disabling a button based on validity

Hi Erik,

Le mardi 25 octobre 2005 à 18:49 +0200, Erik Bruchez a écrit :

> Thanks Andy. It makes sense, and unfortunately (for you and I) falls 
> into the category "here is a way, but it's really a dirty hack" ;-)
> 
> We have done exactly the same things by placing a single event handler 
> higher up the XHTML, to catch all the validation events of a group of 
> controls, and incrementing vs. decrementing a counter. This takes about 
> 10-15 lines of extra code, including the extra instance. I think that 
> ideally such a functionality should be achieved with a single attribute.


This extra-code is not so easy to do for me. And furthermore difficult
since David Landwehr
show me that an event 'xforms-invalid' is dispatched when an invalid
data is changed to a still invalid value.

In the first extra-code I´ve done, the counter was incremented in the
case above ... and it´s wrong of course.
My second extra-code works but is too dirty to be written there.

Shall I see yours, please ?

vinzo.




> 
> So far, we are taking branch #2 in my original question!
> 
> -Erik
> 
> andyh@collegenet.com wrote:
> > 
> > 
> > 
> > 
> > Erik,
> > 
> > This is what we do...
> > 
> > We have an errors instance:
> > 
> > <xf:instance id="iErrors">
> >       <errors xmlns="">
> >             <total>0</total>
> >             <fields>
> >                   <field id="USERNAME">0</field>
> >                   <field id="FIRST_NAME">0</field>
> >                   <field id="LAST_NAME">0</field>
> >                   <field id="EMAIL_ADDRESS">0</field>
> >                   <field id="PASSWORD">0</field>
> >             </fields>
> >             <save/>
> >             <nosave/>
> >       </errors>
> > </xf:instance>
> > 
> > <xf:bind nodeset="/errors/total" calculate="sum(../fields/field)"/>
> > <xf:bind id="bndSave" nodeset="/errors/save" relevant="../total = 0" />
> > <xf:bind id="bndNoSave" nodeset="/errors/nosave" relevant="../total &gt; 0"
> > />
> > 
> > that records the state of each field we need to validate.
> > 
> > Each of those controls have event handlers for xforms-valid and
> > xforms-invalid to set the error count to 0 or 1 respectively.
> > eg.
> > 
> > <xf:input ref="USERNAME" class="SmallTextField" id="f001">
> >       <xf:label>Username:</xf:label>
> >       <xf:alert>Please supply a unique username</xf:alert>
> >       <xf:setvalue model="mErrors"
> > ref="instance('iErrors')/fields/field[@id = 'USERNAME']" value="1"
> > ev:event="xforms-invalid"/>
> >       <xf:setvalue model="mErrors"
> > ref="instance('iErrors')/fields/field[@id = 'USERNAME']" value="0"
> > ev:event="xforms-valid"/>
> > </xf:input>
> > 
> > Finally we have two trigger elements bound to bndSave and bndNoSave. Our
> > styling hides non-relevant controls so only one of these buttons is visible
> > at any point in time. The bndNoSave version has the HTML attribute
> > disabled="disabled" on it so that the button truly looks disabled.
> > 
> > 
> > Now formsPlayer has just introduced an XPath extension function
> > fpext:valid(node-set) [1] that returns true or false of whether a node is
> > valid or not, and this could be used in calculations instead of the event
> > pattern above.
> > 
> > 
> > Andy
> > 
> > [1] http://www.xforms-wiki.com/bin/view/Main/XformsXpathFunctionsExtension
> > 
> > 
> > 
> > 
> >                                                                            
> >              Erik Bruchez                                                  
> >              <erik@bruchez.org                                             
> >              >                                                          To 
> >              Sent by:                  www-forms@w3.org                    
> >              www-forms-request                                          cc 
> >              @w3.org                                                       
> >                                                                    Subject 
> >                                        Disabling a button based on         
> >              10/25/2005 08:32          validity                            
> >              AM                                                            
> >                                                                            
> >                                                                            
> >                                                                            
> >                                                                            
> >                                                                            
> > 
> > 
> > 
> > 
> > 
> > All,
> > 
> > I am having trouble figuring out the solution to an extremely basic UI
> > requirement: disabling a submit button, implemented either with
> > xforms:submit or xforms:trigger, until certain fields have been filled
> > out correctly by the user.
> > 
> > Of course, you could leave the button always enabled. Upon XForms
> > submission, if the submitted instance is not valid or has missing
> > required fields, submission will fail, throw an xforms-submit-error,
> > and you can notify the user of the failure. But from a usability
> > perspective, this is usually a bad solution.
> > 
> > So these are my questions:
> > 
> > 1. How do people address this UI requirement today with XForms? Is
> >     there a way of doing this purely based on the XForms 1.0
> >     specification? If not, are there workarounds? For example, we have
> >     played with counting xforms-valid and xforms-invalid events,
> >     clearly a quite heavy solution.
> > 
> > 2. If the answer to #1 above is "no" or "here is a way, but it's
> >     really a dirty hack":
> > 
> >     2.1. Is the WG working on addressing this? (I should talk with
> >          Sebastian but it doesn't hurt to ask this publicly.)
> > 
> >     2.2. Are there extensions suggested or implemented by existing
> >          XForms engines that address this?
> > 
> > Thanks,
> > 
> > -Erik
> > 
> > 
> > 
> 
> 

-- 
Vincent Berger <vincent.berger@afp.com>
Agence France-Presse

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

This e-mail, and any file transmitted with it, is confidential and  intended solely for the use of the individual or entity to whom it is addressed. If you have received this email in error, please  contact the sender and delete the email from your system. If you are  not the named addressee you should not disseminate, distribute or copy  this email.

For more information on Agence France-Presse, please visit our web site at http://www.afp.com

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Received on Thursday, 27 October 2005 17:21:21 UTC