how to validate a case and bind it to a trigger

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

how to validate a case and bind it to a trigger

c.harder
Hi,
I have a xforms:switch with some cases like your "wizard with switch" example.
Each case has a lot of xforms:input fields which are bound for validation (xforms:bind type="xs:integer").

I thought I could use your "wizard example" for that. But I think its not working like it should do.

For example: If you are in case "age" and you write a letter to input, the error sign is still there, but I can use the finish button. That should only happened if instance is validated.(?)

You have two xforms:action in xforms:input. I have 10-20 xforms:input and I don't like to write it to every input. Is there an other way for that?

How can I solve this?



--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: how to validate a case and bind it to a trigger

Erik Bruchez
Administrator
[hidden email] wrote:

 > I have a xforms:switch with some cases like your "wizard with
 > switch" example.

 > Each case has a lot of xforms:input fields which are bound for
 > validation (xforms:bind type="xs:integer").
 >
 > I thought I could use your "wizard example" for that. But I think
 > its not working like it should do.
 >
 > For example: If you are in case "age" and you write a letter to
 > input, the error sign is still there, but I can use the finish
 > button. That should only happened if instance is validated.(?)
 >
 > You have two xforms:action in xforms:input. I have 10-20
 > xforms:input and I don't like to write it to every input. Is there
 > an other way for that?
 >
 > How can I solve this?

Unfortunately, enabling or disabling a button based on instance
validity cannot be done easily in a cross-platform way. This is one of
the issues we are discussing with the XForms WG. Currently, you have
to use a trick which is illustrated in its simple form, as you have
noticed, in the Wizard example, and ia more complex form, in the Blog
example, i.e. you use an instance just for the purpose of validation:

<xforms:instance id="validity">
     <comment xmlns="">
         <first-name>0</first-name>
         <last-name>0</last-name>
         ...
     </comment>
</xforms:instance>

Then you use a bind to determine the readonly-ness of your trigger:

<xforms:bind nodeset="instance('main')/my-trigger"
              readonly="sum(instance('validity')/*) != 0"/>

<xforms:trigger ref="instance('main')/my-trigger">

Then you need listeners for every control you are monitoring:

<xforms:action ev:event="xforms-invalid">
     <xforms:setvalue ref="instance('validity')/name" value="1"/>
</xforms:action>
<xforms:action ev:event="xforms-valid">
     <xforms:setvalue ref="instance('validity')/name" value="0"/>
</xforms:action>

This is quite heavy, of course, but it works and it is portable. We
think that XForms must provide an easy way of doing this in the future.

-Erik




--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: how to validate a case and bind it to a trigger

c.harder
Hi again,
I've used your way. But there is still a problem. My Example is not working perfect.

1.) My trigger is "readonly" until I put in an integer. Thats ok! But before I can use the trigger, I have to press enter. Its the same on the other side, when name is validated (maybe input: 12) and I put behind that a string (like input: 12f) I can still use the trigger until I've pressed enter.
Is there a way for refreshing after every input?

2.) I've seen in the alert.xhtml example that input field is highlighted red, if  input element is required="true()". Thats seems not working for my example. Whats wrong with it.

Regards
Clemens

<xhtml:html xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:f="http://orbeon.org/oxf/xml/formatting" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:widget="http://orbeon.org/oxf/xml/widget" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xhtml:head>
    <xhtml:title>XForms Alert</xhtml:title>
    <xforms:model xmlns:xforms="http://www.w3.org/2002/xforms">
      <xforms:instance id="main-instance">
        <form>
          <name />
          <age />
        </form>
      </xforms:instance>
      <xforms:instance id="control-instance">
        <instance>
          <my-trigger />
        </instance>
      </xforms:instance>
      <xforms:instance id="validity-instance">
        <instance>
          <name>0</name>
          <age>0</age>
        </instance>
      </xforms:instance>
      <xforms:bind nodeset="instance('main-instance')/name" type="xs:integer" required="true()" />
      <xforms:bind nodeset="instance('control-instance')/my-trigger" readonly="sum(instance('validity-instance')/*) != 0" />
    </xforms:model>
  </xhtml:head>
  <xhtml:body>
    <xhtml:h3>Switch</xhtml:h3>
    <xforms:switch>
      <xforms:case id="case1">
        <xhtml:table class="gridtable">
          <xhtml:tr>
            <xhtml:td>Name:</xhtml:td>
            <xhtml:td>
              <xforms:input ref="instance('main-instance')/name">
                <xforms:label />
                <xforms:action ev:event="xforms-invalid">
                  <xforms:setvalue ref="instance('validity-instance')/name" value="1" />
                </xforms:action>
                <xforms:action ev:event="xforms-valid">
                  <xforms:setvalue ref="instance('validity-instance')/name" value="0" />
                </xforms:action>
              </xforms:input>
            </xhtml:td>
          </xhtml:tr>
          <xhtml:tr>
            <xhtml:td>Age:</xhtml:td>
            <xhtml:td>
              <xforms:input ref="instance('main-instance')/age">
                <xforms:label />
                <xforms:action ev:event="xforms-invalid">
                  <xforms:setvalue ref="instance('validity-instance')/age" value="1" />
                </xforms:action>
                <xforms:action ev:event="xforms-valid">
                  <xforms:setvalue ref="instance('validity-instance')/age" value="0" />
                </xforms:action>
              </xforms:input>
            </xhtml:td>
          </xhtml:tr>
        </xhtml:table>
        <xforms:trigger ref="instance('control-instance')/my-trigger">
          <xforms:label>Case 2</xforms:label>
          <xforms:toggle case="case2" ev:event="DOMActivate"/>
        </xforms:trigger>
      </xforms:case>
      <xforms:case id="case2">
        <xforms:trigger>
          <xforms:label>Case 1</xforms:label>
          <xforms:toggle case="case1" ev:event="DOMActivate" />
        </xforms:trigger>
      </xforms:case>
    </xforms:switch>
  </xhtml:body>
</xhtml:html>



--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: how to validate a case and bind it to a trigger

c.harder
     
There was an error in "validity-instance":

<xforms:instance id="validity-instance">
        <instance>
          <name>1</name>
          <age>0</age>
        </instance>
      </xforms:instance>

Without name=1 you can use the trigger with no input, while name is required.



--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: how to validate a case and bind it to a trigger

c.harder
Hi,
is there no solution for that problem?

My last mail in that thread was not the solution, it was only a "patch" for my example. ;-)

Please can some try it and give me a hint how to solve.

Thanks



--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: how to validate a case and bind it to a trigger

Erik Bruchez
Administrator
In reply to this post by c.harder
[hidden email] wrote:

 > I've used your way. But there is still a problem. My Example is not
 > working perfect.
 >
 > 1.) My trigger is "readonly" until I put in an integer. Thats ok!
 > But before I can use the trigger, I have to press enter. Its the
 > same on the other side, when name is validated (maybe input: 12) and
 > I put behind that a string (like input: 12f) I can still use the
 > trigger until I've pressed enter.  Is there a way for refreshing
 > after every input?

You can use the incremental="true" attribute on the input field. This
causes the text field to send xforms-value-change events "from time to
time", which will cause your trigger to be updated as you type.

 > 2.) I've seen in the alert.xhtml example that input field is
 > 2.highlighted red, if input element is required="true()". Thats
 > 2.seems not working for my example. Whats wrong with it.

There seems to be a problem here. It works in some cases, but not
all. I have entered a bug to track this:

http://forge.objectweb.org/tracker/index.php?func=detail&aid=304336&group_id=168&atid=350207

-Erik




--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws