I've been puzzling through getting the "submit" button on my prototype to dynamically turn on and off depending on the validity of the data filled in the form. I've carefully compared with examples shipped with the app and published in the blog, and it's still not quite working.
One particular problem is that when I click a checkbox on an otherwise invalid form, "xforms-valid" is fired! I've attached a very stripped-down version of my app. It has a bunch of extra xforms:message tags to help suss out what's going on. When I run it (using the 3_6_0_200712061930 release under Tomcat 5.5), the form displays as I'd expect (an entry field with an error, a checkbox, and a disabled submit button). When I click the checkbox the following succession of message dialogs come up: * xforms-value-changed - pre - valid='true' dirty='false' * xforms-value-changed - post - valid='true' dirty='true' * xforms-valid - pre - valid='true' dirty='true' * xforms-valid - post - valid='true' dirty='true' I'm not sure why "valid='true'" right from the start, given the form is invalid and the button is disabled. And why is "xforms-valid" thrown, instead of "xforms-invalid"? Interestingly, if I change my document by removing the xforms:setvalue from the xforms-valid handler, then it kind of works: the button stays disabled, and "valid='false'"... though still it's "valid" event instead of the "invalid" event being thrown. Am I misunderstanding something? Thanks! rodney ===== my page =================== <?xml version="1.0" encoding="UTF-8"?> <xhtml:html xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"> <xhtml:head> <xhtml:title>Rodney's Static Sample</xhtml:title> <xforms:model> <xforms:instance id="custom_model"> <udf> <form> <answer id="1.2"/> <answer id="1.4">false</answer> </form> </udf> </xforms:instance> <xforms:bind nodeset="instance('custom_model')"> <xforms:bind nodeset="/udf/form/answer[@id='1.2']" type="xs:integer" required="true()"/> <xforms:bind nodeset="/udf/form/answer[@id='1.4']" type="xs:boolean"/> </xforms:bind> <xforms:instance id="control-instance"> <control-instance> <valid/> <dirty>false</dirty> <submit_button/> </control-instance> </xforms:instance> <xforms:bind nodeset="instance('control-instance')/submit_button" readonly="not( ( ../dirty = 'true' ) and ( ../valid = 'true' ) )"/> </xforms:model> </xhtml:head> <xhtml:body> <xhtml:table cellpadding="3"> <xforms:group> <xforms:action ev:event="xforms-valid"> <xforms:message>xforms-valid - pre - valid='<xforms:output ref="instance('control-instance')/valid"/>' dirty='<xforms:output ref="instance('control-instance')/dirty"/>'</xforms:message> <xforms:setvalue ref="instance('control-instance')/valid">true</xforms:setvalue> <xforms:message>xforms-valid - post - valid='<xforms:output ref="instance('control-instance')/valid"/>' dirty='<xforms:output ref="instance('control-instance')/dirty"/>'</xforms:message> </xforms:action> <xforms:action ev:event="xforms-invalid"> <xforms:message>xforms-invalid - pre - valid='<xforms:output ref="instance('control-instance')/valid"/>' dirty='<xforms:output ref="instance('control-instance')/dirty"/>'</xforms:message> <xforms:setvalue ref="instance('control-instance')/valid">false</xforms:setvalue> <xforms:message>xforms-invalid - post - valid='<xforms:output ref="instance('control-instance')/valid"/>' dirty='<xforms:output ref="instance('control-instance')/dirty"/>'</xforms:message> </xforms:action> <xforms:action ev:event="xforms-value-changed"> <xforms:message>xforms-value-changed - pre - valid='<xforms:output ref="instance('control-instance')/valid"/>' dirty='<xforms:output ref="instance('control-instance')/dirty"/>'</xforms:message> <xforms:setvalue ref="instance('control-instance')/dirty">true</xforms:setvalue> <xforms:message>xforms-value-changed - post - valid='<xforms:output ref="instance('control-instance')/valid"/>' dirty='<xforms:output ref="instance('control-instance')/dirty"/>'</xforms:message> </xforms:action> | This is the first section Integer question: | <xforms:input incremental="true" ref="/udf/form/answer[@id='1.2']"/> | Generic checkbox: | <xforms:input incremental="true" ref="/udf/form/answer[@id='1.4']"/> | <p/> | </xforms:group> <xhtml:tr> <xhtml:td colspan="3"> <xforms:trigger ref="instance('control-instance')/submit_button"> <xforms:label>Submit</xforms:label> </xforms:trigger> </xhtml:td> </xhtml:tr> </xhtml:table> </xhtml:body> </xhtml:html> |
HI Rodney,
I did the same thing today... Basically I was looking at the government forms application to help me out... I read in a book that xforms-valid is control based... so its triggered when a control is valid... not when the whole form is valid. What I did was 1. Trigger a revalidate when it first loaded up... that way... I did not need to track if the data was dirty <!-- This is called when the XForms engine is ready --> <xforms:action ev:event="xforms-ready"> <!-- Load document if specified --> <xforms:revalidate/> </xforms:action> 2. I used the same error handling as in the government forms to keep track of the errors in an instance.. Then inside of the xforms-valid event handler added the below code <xforms:action if="count(instance('errors-instance')/error)=0"> <xforms:toggle case="allow-submit" /> </xforms:action> I used a Switch to trigger which "save" button to show... You could also bind the trigger to a instance and make it read only using the bind... which is how they do it in government forms... I hope this helps! Regards Mark On Fri, Mar 7, 2008 at 6:55 PM, Rodney Gitzel <[hidden email]> wrote:
-- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Administrator
|
Mark, Rodney:
Yes, these UI events can be a little daunting. You are right, they are fired per control. They do not indicate whether the entire form is valid or not. We are currently working on making this simpler by providing a reusable model for error summaries, among other features (think the Government Forms example but done much better). We already have a lot under RESOURCES/apps/fr/ if you are curious. -Erik On Mar 7, 2008, at 10:10 AM, Mark Ellul wrote: > HI Rodney, > > I did the same thing today... Basically I was looking at the > government forms application to help me out... > > I read in a book that xforms-valid is control based... so its > triggered when a control is valid... not when the whole form is valid. > > What I did was > 1. Trigger a revalidate when it first loaded up... that way... I did > not need to track if the data was dirty > > <!-- This is called when the XForms engine is ready --> > <xforms:action ev:event="xforms-ready"> > <!-- Load document if specified --> > <xforms:revalidate/> > </xforms:action> > > 2. I used the same error handling as in the government forms to keep > track of the errors in an instance.. Then inside of the xforms-valid > event handler added the below code > > <xforms:action if="count(instance('errors-instance')/ > error)=0"> > <xforms:toggle case="allow-submit" /> > </xforms:action> > > > I used a Switch to trigger which "save" button to show... You could > also bind the trigger to a instance and make it read only using the > bind... which is how they do it in government forms... > > I hope this helps! > > Regards > > Mark > > On Fri, Mar 7, 2008 at 6:55 PM, Rodney Gitzel <[hidden email]> > wrote: > > I've been puzzling through getting the "submit" button on my > prototype to > dynamically turn on and off depending on the validity of the data > filled in > the form. I've carefully compared with examples shipped with the > app and > published in the blog, and it's still not quite working. > > One particular problem is that when I click a checkbox on an otherwise > invalid form, "xforms-valid" is fired! > > I've attached a very stripped-down version of my app. It has a > bunch of > extra xforms:message tags to help suss out what's going on. When I > run it > (using the 3_6_0_200712061930 release under Tomcat 5.5), the form > displays > as I'd expect (an entry field with an error, a checkbox, and a > disabled > submit button). > > When I click the checkbox the following succession of message > dialogs come > up: > > * xforms-value-changed - pre - valid='true' dirty='false' > * xforms-value-changed - post - valid='true' dirty='true' > * xforms-valid - pre - valid='true' dirty='true' > * xforms-valid - post - valid='true' dirty='true' > > I'm not sure why "valid='true'" right from the start, given the form > is > invalid and the button is disabled. And why is "xforms-valid" thrown, > instead of "xforms-invalid"? > > Interestingly, if I change my document by removing the > xforms:setvalue from > the xforms-valid handler, then it kind of works: the button stays > disabled, > and "valid='false'"... though still it's "valid" event instead of the > "invalid" event being thrown. > > Am I misunderstanding something? > > Thanks! > > rodney > > > ===== my page =================== > > <?xml version="1.0" encoding="UTF-8"?> > <xhtml:html xmlns:ev="http://www.w3.org/2001/xml-events" > xmlns:xforms="http://www.w3.org/2002/xforms" > xmlns:xhtml="http://www.w3.org/1999/xhtml" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"> > > <xhtml:head> > <xhtml:title>Rodney's Static Sample</xhtml:title> > <xforms:model> > > <xforms:instance id="custom_model"> > <udf> > <form> > <answer id="1.2"/> > <answer id="1.4">false</answer> > </form> > </udf> > </xforms:instance> > > <xforms:bind nodeset="instance('custom_model')"> > <xforms:bind nodeset="/udf/form/answer[@id='1.2']" > type="xs:integer" required="true()"/> > <xforms:bind nodeset="/udf/form/answer[@id='1.4']" > type="xs:boolean"/> > </xforms:bind> > > <xforms:instance id="control-instance"> > <control-instance> > <valid/> > <dirty>false</dirty> > <submit_button/> > </control-instance> > </xforms:instance> > <xforms:bind > nodeset="instance('control-instance')/submit_button" > readonly="not( ( ../dirty = 'true' ) and ( ../valid = 'true' ) )"/> > > </xforms:model> > </xhtml:head> > > <!-- > = > = > = > = > = > = > = > = > = > = > = > = > = > = > = > = > ====================================================================== > --> > > <xhtml:body> > > <xhtml:table cellpadding="3"> > > <xforms:group> > > <xforms:action ev:event="xforms-valid"> > <xforms:message>xforms-valid - pre - > valid='<xforms:output > ref="instance('control-instance')/valid"/>' dirty='<xforms:output > ref="instance('control-instance')/dirty"/>'</xforms:message> > <xforms:setvalue > ref="instance('control-instance')/valid">true</xforms:setvalue> > <xforms:message>xforms-valid - post - > valid='<xforms:output ref="instance('control-instance')/valid"/>' > dirty='<xforms:output > ref="instance('control-instance')/dirty"/>'</xforms:message> > </xforms:action> > > <xforms:action ev:event="xforms-invalid"> > <xforms:message>xforms-invalid - pre - > valid='<xforms:output ref="instance('control-instance')/valid"/>' > dirty='<xforms:output > ref="instance('control-instance')/dirty"/>'</xforms:message> > <xforms:setvalue > ref="instance('control-instance')/valid">false</xforms:setvalue> > <xforms:message>xforms-invalid - post - > valid='<xforms:output ref="instance('control-instance')/valid"/>' > dirty='<xforms:output > ref="instance('control-instance')/dirty"/>'</xforms:message> > </xforms:action> > > <xforms:action ev:event="xforms-value-changed"> > <xforms:message>xforms-value-changed - pre - > valid='<xforms:output ref="instance('control-instance')/valid"/>' > dirty='<xforms:output > ref="instance('control-instance')/dirty"/>'</xforms:message> > <xforms:setvalue > ref="instance('control-instance')/dirty">true</xforms:setvalue> > <xforms:message>xforms-value-changed - post - > valid='<xforms:output ref="instance('control-instance')/valid"/>' > dirty='<xforms:output > ref="instance('control-instance')/dirty"/>'</xforms:message> > </xforms:action> > > <tr> > <td colspan="2" width="150"> > > This is the first section > > </td> > </tr> > <tr id="row_1.2"> > <td width="150"> > Integer question: > </td> > <td> > <xforms:input incremental="true" > ref="/udf/form/answer[@id='1.2']"/> > </td> > </tr> > <tr id="row_1.4"> > <td width="150"> > Generic checkbox: > </td> > <td> > <xforms:input incremental="true" > ref="/udf/form/answer[@id='1.4']"/> > </td> > </tr> > <tr> > <td colspan="2" width="150"> > <p/> > </td> > </tr> > > </xforms:group> > > <xhtml:tr> > <xhtml:td colspan="3"> > <xforms:trigger > ref="instance('control-instance')/submit_button"> > <xforms:label>Submit</xforms:label> > </xforms:trigger> > </xhtml:td> > </xhtml:tr> > > </xhtml:table> > > </xhtml:body> > </xhtml:html> Orbeon Forms - Web Forms for the Enterprise Done the Right Way http://www.orbeon.com/ -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Hi Eric,
Yes I guess the ability to know if the form is valid could be made more simple... Maybe a new event we can trigger actions from to know if the model is dirty and valid? Regards Mark On Fri, Mar 7, 2008 at 7:34 PM, Erik Bruchez <[hidden email]> wrote: Mark, Rodney: -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Administrator
|
You can actually figure it out with the existing events, although it
requires some work. That's what we the Govt Forms example does now, and what our work in progress under RESOURCES/apps/fr/ formalizes. -Erik On Mar 7, 2008, at 10:47 AM, Mark Ellul wrote: > Hi Eric, > > Yes I guess the ability to know if the form is valid could be made > more simple... > > Maybe a new event we can trigger actions from to know if the model > is dirty and valid? > > Regards > > Mark > > On Fri, Mar 7, 2008 at 7:34 PM, Erik Bruchez <[hidden email]> > wrote: > Mark, Rodney: > > Yes, these UI events can be a little daunting. > > You are right, they are fired per control. They do not indicate > whether the entire form is valid or not. > > We are currently working on making this simpler by providing a > reusable model for error summaries, among other features (think the > Government Forms example but done much better). We already have a lot > under RESOURCES/apps/fr/ if you are curious. > > -Erik > > On Mar 7, 2008, at 10:10 AM, Mark Ellul wrote: > > > HI Rodney, > > > > I did the same thing today... Basically I was looking at the > > government forms application to help me out... > > > > I read in a book that xforms-valid is control based... so its > > triggered when a control is valid... not when the whole form is > valid. > > > > What I did was > > 1. Trigger a revalidate when it first loaded up... that way... I did > > not need to track if the data was dirty > > > > <!-- This is called when the XForms engine is ready --> > > <xforms:action ev:event="xforms-ready"> > > <!-- Load document if specified --> > > <xforms:revalidate/> > > </xforms:action> > > > > 2. I used the same error handling as in the government forms to keep > > track of the errors in an instance.. Then inside of the xforms-valid > > event handler added the below code > > > > <xforms:action if="count(instance('errors- > instance')/ > > error)=0"> > > <xforms:toggle case="allow-submit" /> > > </xforms:action> > > > > > > I used a Switch to trigger which "save" button to show... You could > > also bind the trigger to a instance and make it read only using the > > bind... which is how they do it in government forms... > > > > I hope this helps! > > > > Regards > > > > Mark > > > > On Fri, Mar 7, 2008 at 6:55 PM, Rodney Gitzel <[hidden email]> > > wrote: > > > > I've been puzzling through getting the "submit" button on my > > prototype to > > dynamically turn on and off depending on the validity of the data > > filled in > > the form. I've carefully compared with examples shipped with the > > app and > > published in the blog, and it's still not quite working. > > > > One particular problem is that when I click a checkbox on an > otherwise > > invalid form, "xforms-valid" is fired! > > > > I've attached a very stripped-down version of my app. It has a > > bunch of > > extra xforms:message tags to help suss out what's going on. When I > > run it > > (using the 3_6_0_200712061930 release under Tomcat 5.5), the form > > displays > > as I'd expect (an entry field with an error, a checkbox, and a > > disabled > > submit button). > > > > When I click the checkbox the following succession of message > > dialogs come > > up: > > > > * xforms-value-changed - pre - valid='true' dirty='false' > > * xforms-value-changed - post - valid='true' dirty='true' > > * xforms-valid - pre - valid='true' dirty='true' > > * xforms-valid - post - valid='true' dirty='true' > > > > I'm not sure why "valid='true'" right from the start, given the form > > is > > invalid and the button is disabled. And why is "xforms-valid" > thrown, > > instead of "xforms-invalid"? > > > > Interestingly, if I change my document by removing the > > xforms:setvalue from > > the xforms-valid handler, then it kind of works: the button stays > > disabled, > > and "valid='false'"... though still it's "valid" event instead of > the > > "invalid" event being thrown. > > > > Am I misunderstanding something? > > > > Thanks! > > > > rodney > > > > > > ===== my page =================== > > > > <?xml version="1.0" encoding="UTF-8"?> > > <xhtml:html xmlns:ev="http://www.w3.org/2001/xml-events" > > xmlns:xforms="http://www.w3.org/2002/xforms" > > xmlns:xhtml="http://www.w3.org/1999/xhtml" > > xmlns:xs="http://www.w3.org/2001/XMLSchema" > > xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"> > > > > <xhtml:head> > > <xhtml:title>Rodney's Static Sample</xhtml:title> > > <xforms:model> > > > > <xforms:instance id="custom_model"> > > <udf> > > <form> > > <answer id="1.2"/> > > <answer id="1.4">false</answer> > > </form> > > </udf> > > </xforms:instance> > > > > <xforms:bind nodeset="instance('custom_model')"> > > <xforms:bind nodeset="/udf/form/answer[@id='1.2']" > > type="xs:integer" required="true()"/> > > <xforms:bind nodeset="/udf/form/answer[@id='1.4']" > > type="xs:boolean"/> > > </xforms:bind> > > > > <xforms:instance id="control-instance"> > > <control-instance> > > <valid/> > > <dirty>false</dirty> > > <submit_button/> > > </control-instance> > > </xforms:instance> > > <xforms:bind > > nodeset="instance('control-instance')/submit_button" > > readonly="not( ( ../dirty = 'true' ) and ( ../valid = 'true' ) )"/> > > > > </xforms:model> > > </xhtml:head> > > > > <!-- > > = > > = > > = > > = > > = > > = > > = > > = > > = > > = > > = > > = > > = > > = > > = > > = > > > ====================================================================== > > --> > > > > <xhtml:body> > > > > <xhtml:table cellpadding="3"> > > > > <xforms:group> > > > > <xforms:action ev:event="xforms-valid"> > > <xforms:message>xforms-valid - pre - > > valid='<xforms:output > > ref="instance('control-instance')/valid"/>' dirty='<xforms:output > > ref="instance('control-instance')/dirty"/>'</xforms:message> > > <xforms:setvalue > > ref="instance('control-instance')/valid">true</xforms:setvalue> > > <xforms:message>xforms-valid - post - > > valid='<xforms:output ref="instance('control-instance')/valid"/>' > > dirty='<xforms:output > > ref="instance('control-instance')/dirty"/>'</xforms:message> > > </xforms:action> > > > > <xforms:action ev:event="xforms-invalid"> > > <xforms:message>xforms-invalid - pre - > > valid='<xforms:output ref="instance('control-instance')/valid"/>' > > dirty='<xforms:output > > ref="instance('control-instance')/dirty"/>'</xforms:message> > > <xforms:setvalue > > ref="instance('control-instance')/valid">false</xforms:setvalue> > > <xforms:message>xforms-invalid - post - > > valid='<xforms:output ref="instance('control-instance')/valid"/>' > > dirty='<xforms:output > > ref="instance('control-instance')/dirty"/>'</xforms:message> > > </xforms:action> > > > > <xforms:action ev:event="xforms-value-changed"> > > <xforms:message>xforms-value-changed - pre - > > valid='<xforms:output ref="instance('control-instance')/valid"/>' > > dirty='<xforms:output > > ref="instance('control-instance')/dirty"/>'</xforms:message> > > <xforms:setvalue > > ref="instance('control-instance')/dirty">true</xforms:setvalue> > > <xforms:message>xforms-value-changed - post - > > valid='<xforms:output ref="instance('control-instance')/valid"/>' > > dirty='<xforms:output > > ref="instance('control-instance')/dirty"/>'</xforms:message> > > </xforms:action> > > > > <tr> > > <td colspan="2" width="150"> > > > > This is the first section > > > > </td> > > </tr> > > <tr id="row_1.2"> > > <td width="150"> > > Integer question: > > </td> > > <td> > > <xforms:input incremental="true" > > ref="/udf/form/answer[@id='1.2']"/> > > </td> > > </tr> > > <tr id="row_1.4"> > > <td width="150"> > > Generic checkbox: > > </td> > > <td> > > <xforms:input incremental="true" > > ref="/udf/form/answer[@id='1.4']"/> > > </td> > > </tr> > > <tr> > > <td colspan="2" width="150"> > > <p/> > > </td> > > </tr> > > > > </xforms:group> > > > > <xhtml:tr> > > <xhtml:td colspan="3"> > > <xforms:trigger > > ref="instance('control-instance')/submit_button"> > > <xforms:label>Submit</xforms:label> > > </xforms:trigger> > > </xhtml:td> > > </xhtml:tr> > > > > </xhtml:table> > > > > </xhtml:body> > > </xhtml:html> > > -- > Orbeon Forms - Web Forms for the Enterprise Done the Right Way > http://www.orbeon.com/ > > > > -- > You receive this message as a subscriber of the [hidden email] > mailing list. > To unsubscribe: mailto:[hidden email] > For general help: mailto:[hidden email]?subject=help > OW2 mailing lists service home page: http://www.ow2.org/wws > > > > -- > You receive this message as a subscriber of the [hidden email] > mailing list. > To unsubscribe: mailto:[hidden email] > For general help: mailto:[hidden email]?subject=help > OW2 mailing lists service home page: http://www.ow2.org/wws Orbeon Forms - Web Forms for the Enterprise Done the Right Way http://www.orbeon.com/ -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
Hi Erik,
I have done it the Govt Forms way... it seems to work a treat... though it would be good if that complexity was simplifed... But it works so I am not complaining... Regards Mark On Fri, Mar 7, 2008 at 7:52 PM, Erik Bruchez <[hidden email]> wrote: You can actually figure it out with the existing events, although it -- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: mailto:[hidden email] For general help: mailto:[hidden email]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws |
In reply to this post by Erik Bruchez
Bingo! That definitely explains what I was seeing.
And now the submit button in my prototype flickers off and on appropriately, at least it did once I removed all the error messages that I don't have yet. Thanks! :-) rodney
|
Free forum by Nabble | Edit this page |