show error message in DNI javascript validation

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

show error message in DNI javascript validation

aitor
Hello,

I am doing a .xbl component that is an input box that performs a javascript validation (dni validation) when the input value change: ev:event="xforms-value-changed". What I want to know is: Are there any javascript function that shows the input error in the error summary section and next to the input field?. The code that I have to catch the event is:

<xforms:input ref="$result" id="dni-input" class="xbl-fr-dni-xforms-input fr-hidden">
  <xforms:label>Dni</xforms:label>
  <xforms:alert>The dni is not correct.</xforms:alert>
  <xxforms:script id="xf-ch" ev:event="xforms-value-changed xxforms-iteration-moved">
        if (!isDNI(this.value)){
                alert('The dni is not correct.: ' + this.value);
        }
  </xxforms:script>
</xforms:input>
                           
Instead of the "alert('The dni is not correct.: ' + this.value)" I want to show the error message of the "<xforms:alert>" in the summary error section and next to the input field.

Or, if there is no javascript function to do it. How can I do it in other way. Doing the validation in the class for example.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: show error message in DNI javascript validation

aitor
Sorry, the code is:
<xforms:input ref="$result" id="dni-input" class="xbl-fr-dni-xforms-input fr-hidden">
  <xforms:label>Dni</xforms:label>
  <xforms:alert>The dni is not correct.</xforms:alert>
  <xxforms:script id="xf-ch" ev:event="xforms-value-changed xxforms-iteration-moved">
        if (!isDNI(this.value)){
                alert('The dni is not correct.: ' + this.value);
        }
  </xxforms:script>
</xforms:input>

Instead of the "alert('The dni is not correct.: ' + this.value)" I want to show the error message of the "<xforms:alert>" in the summary error section and next to the input field.
Reply | Threaded
Open this post in threaded view
|

Re: show error message in DNI javascript validation

fl.schmitt(ops-users)
In reply to this post by aitor
aitor,

maybe you could combine a bind/@constraint and a setValue: Your
javascript Validation function issues a
ORBEON.xforms.Document.setValue('validationresult', false), thus setting
the value of an instance element to false. That element is "monitored"
using a bind/@constraint on the "result" element, comparing the value of
the control element with a literal 'false'. This way, the validation of
the "result" element depends on the content of the validationresult
element, and you can set it using javascript.

HTH
florian




--
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
Reply | Threaded
Open this post in threaded view
|

Re: Re: show error message in DNI javascript validation

Erik Bruchez
Administrator
I think this would be the right approach, i.e. the JavaScript telling XForms that the field is invalid. Then the usual validity mechanism of XForms kicks in.

-Erik

On Tue, Mar 15, 2011 at 7:53 AM, Florian Schmitt <[hidden email]> wrote:
aitor,

maybe you could combine a bind/@constraint and a setValue: Your
javascript Validation function issues a
ORBEON.xforms.Document.setValue('validationresult', false), thus setting
the value of an instance element to false. That element is "monitored"
using a bind/@constraint on the "result" element, comparing the value of
the control element with a literal 'false'. This way, the validation of
the "result" element depends on the content of the validationresult
element, and you can set it using javascript.

HTH
florian




--
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
Reply | Threaded
Open this post in threaded view
|

Re: Re: show error message in DNI javascript validation

aitor
I don't know if I understand the answer. I create other input field ('dni-input-auxiliar') that is what is showing the alert message when the value is false. But it doesn't show the message. My code is:
 <xxforms:variable name="result" as="node()?">
  <xxforms:sequence select="." xxbl:scope="outer"/>
 </xxforms:variable>
   
 <xforms:input ref="$result" name="dni-input" id="dni-input" class="xbl-fr-dni-xforms-input fr-hidden">
 <xxforms:script id="xf-ch" ev:event="xforms-value-changed">
        if (!isDNI(this.value)){
        ORBEON.xforms.Document.setValue(this.id + '-auxiliar', 'false');
        } else {
        ORBEON.xforms.Document.setValue(this.id + '-auxiliar', 'true');
        }
    </xxforms:script>
 </xforms:input>

 <xforms:input ref="dni-input-auxiliar" name="dni-input-auxiliar" id="dni-input-auxiliar">
   <xforms:label>Prueba DNI.</xforms:label>
   <xforms:alert>El dni no es correcto.</xforms:alert>
 </xforms:input>
 <xf:bind ref="dni-input-auxiliar" constraint=". = ('true')" />
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: show error message in DNI javascript validation

fl.schmitt(ops-users)
aitor,

trying to implement it myself, i found it's not as easy as i thought
yesterday. It would be quite trivial with plain XForms, but the problem
is the encapsulation into a XBL.

Writing the result of the javascript validation function into a xforms
instance element (here: dni-input-auxiliar) requires a corresponding
xforms:input (as in your code: xforms:input/@id=dni-input-auxiliar).

If we place that auxiliar input control into the XBL, i suppose we'll
have to place the xforms:bind into the XBL, too. But the xforms:bind
needs to have access to the value of the control with id "dni-input".

So i think another "layer" is required: we need to put the current DNI
value into the local model, too. So, our XBL has three xforms:input
controls:
- xforms-input, hidden, referencing the external single-node-binding;
writes its value into the local model on init and xforms-value-changed;
- auxiliary-input, hidden, holds the validation result, bound to the
local model;
- visible-input, bound to the local model, lets user enter / modify the
DNI, writes its value to xforms-input on xforms-value-changed.

I'm not sure wether there's a better way to connect the local model with
the external model, but at least it seems to work ;)

I've attached a sample XBL together with a javascript and a sandbox page
as "testing environment".

HTH
florian



--
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

dni.js (3K) Download Attachment
dni.xbl (3K) Download Attachment
xbl-dni.xhtml (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: show error message in DNI javascript validation

aitor
Thank you very much Florian, this is I wanted to do.
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: show error message in DNI javascript validation

aitor
I have other cuestion about the internationalization in this dni's example. When I add the dni's xbl's component in the Form Builder and I traslate the component in various languages. The component label is shown fine, but when I enter an invalid input, in the summary errors don't show an error message of the alert I entered in the Form Builder, neither the label. How can I code it to show in the summary error the error message that I write in the alert and the label?
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: show error message in DNI javascript validation

Erik Bruchez
Administrator
In Fom Builder, in the validation properties, the alert message
depends on the current language selected for the edition of the form.

Did you try switching to the other language first, then opening the
validation properties?

-Erik

On Wed, Mar 23, 2011 at 1:50 AM, aitor <[hidden email]> wrote:

> I have other cuestion about the internationalization in this dni's example.
> When I add the dni's xbl's component in the Form Builder and I traslate the
> component in various languages. The component label is shown fine, but when
> I enter an invalid input, in the summary errors don't show an error message
> of the alert I entered in the Form Builder, neither the label. How can I
> code it to show in the summary error the error message that I write in the
> alert and the label?
>
> --
> View this message in context: http://orbeon-forms-ops-users.24843.n4.nabble.com/show-error-message-in-DNI-javascript-validation-tp3356731p3398880.html
> Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.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
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: show error message in DNI javascript validation

aitor
Hello Erik,
Sorry about the delay in the response. In Fom Builder, in the validation properties I enter the values in the alert messages but it doesn't show the error that I have entered in any language .
To show this alert error I try with this code to link the alert in the XBL with the input in the form that I added the XBL component:
<xforms:input ref="value" class="xbl-fr-dni-visible-input">
        <xforms:alert><xforms:output value="$binding/alert"/></xforms:alert>
...
</xforms:input>
I attach the code in the xbl file.
dni.xbl

But it doesn't work. Does anybody know how to show this summary error in the form.

And other thing is that when I send a mail clicking in the form's Email buttom in the form, the value that I have entered in the dni's input box doesn't show in the mail.
The same happend when I add the currency's XBL component in the form; the value that I have entered doesn't show in the mail that is send.

Thanks,