Enable / disable button with error-summary

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

Enable / disable button with error-summary

Ruben Garay
Hi Alex! I'm making an example, in App Buider 2016.3. It consists of the use of fr:error-summary and counting the number of errors, if the number of errors of the controls is greater than zero the button is read only. If the number of errors is equal to zero, it is activated. Currently if you count the number of errors, but the problem is that once you enter a valid data in some field, the summary error is not updated, it continues showing the total of initial errors. I based on the following link: https://gist.github.com/dmccreary/1f342729337d7685f6b0 I add the code:
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
         xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
         xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
         xmlns:saxon="http://saxon.sf.net/"
         xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
         xmlns:xf="http://www.w3.org/2002/xforms"
         xmlns:sql="http://orbeon.org/oxf/xml/sql"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:xi="http://www.w3.org/2001/XInclude"
         xmlns:ev="http://www.w3.org/2001/xml-events"
         xmlns:exf="http://www.exforms.org/exf/1-0"
         xmlns:xs="http://www.w3.org/2001/XMLSchema"
         xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
         xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <xh:head>
        <xh:title>Count</xh:title>
        <xf:model id="fr-form-model" xxf:expose-xpath-types="true">

            <!-- Main instance -->
            <xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
                <form>
                    <section-1>
                        <integer1/>
                        <integer2/>
                        <integer3/>
                        <save/>
                        <errorCount/>
                    </section-1>
                </form>
            </xf:instance>
            
            <!-- Control instance -->
            <xf:instance id="control-instance">
                <control>
                    <!-- Note that we have to initialize this to 0 for the initial compare to work.  Type should be integer. -->
                    <error-count>3</error-count>
                </control>
            </xf:instance>

            <!-- Bindings -->
            <xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
                <xf:bind id="section-1-bind" name="section-1" ref="section-1">
                    <xf:bind id="integer1-bind" name="integer1" ref="integer1" xxf:whitespace="trim"
                             type="xs:integer"
                             required="true()"/>
                    <xf:bind id="integer2-bind" ref="integer2" name="integer2" type="xs:integer"
                             required="true()"/>
                    <xf:bind id="integer3-bind" ref="integer3" name="integer3" type="xs:integer"
                             required="true()"/>
                    <xf:bind id="errorCount-bind" ref="errorCount" name="errorCount"
                             calculate="instance('control-instance')/error-count"/>
                    <xf:bind id="save-bind" ref="save" name="save"
                             readonly="xs:integer(instance('control-instance')/error-count) gt 0"/>
                </xf:bind>
            </xf:bind>

            <!-- Metadata -->
            <xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
                <metadata>
                    <application-name>countErrors</application-name>
                    <form-name>errorCount</form-name>
                    <title xml:lang="en">Count</title>
                    <description xml:lang="en"/>
                </metadata>
            </xf:instance>

            <!-- Attachments -->
            <xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
                <attachments>
                    <css mediatype="text/css" filename="" size=""/>
                    <pdf mediatype="application/pdf" filename="" size=""/>
                </attachments>
            </xf:instance>

            <!-- All form resources -->
            <xf:instance xxf:readonly="true" id="fr-form-resources" xxf:exclude-result-prefixes="#all">
                <resources>
                    <resource xml:lang="en">
                        <section-1>
                            <label>Count errors</label>
                        </section-1>
                        <integer1>
                            <label>Integer 1</label>
                            <hint/>
                        </integer1>
                        <integer2>
                            <label>Integer 2</label>
                            <hint/>
                        </integer2>
                        <integer3>
                            <label>Integer 3</label>
                            <hint/>
                        </integer3>
                        
                        <save>
                            <label>Save</label>
                            <hint/>
                        </save>
                        <errorCount>
                            <label>Error count:</label>
                            <hint/>
                        </errorCount>
                    </resource>
                </resources>
            </xf:instance>

            <!-- Utility instances for services -->
            <xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all">
                <request/>
            </xf:instance>
            <xf:instance id="fr-service-response-instance" xxf:exclude-result-prefixes="#all">
                <response/>
            </xf:instance>
            
        </xf:model>
    </xh:head>
    <xh:body>
        <fr:view>
            <fr:body xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xbl="http://www.w3.org/ns/xbl"
                     xmlns:oxf="http://www.orbeon.com/oxf/processors">
                <fr:section id="section-1-control" bind="section-1-bind">
                    <xf:label ref="$form-resources/section-1/label"/>
                    <xf:group id="error-summary-group">
                        <fr:grid>
                            <xh:tr>
                                <xh:td>
                                    <fr:number xmlns="http://orbeon.org/oxf/xml/form-builder"
                                               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                               xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
                                               id="integer1-control"
                                               bind="integer1-bind">
                                        <xf:label ref="$form-resources/integer1/label"/>
                                        <xf:hint ref="$form-resources/integer1/hint"/>
                                        <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                    </fr:number>
                                </xh:td>
                                <xh:td/>
                                <xh:td/>
                                <xh:td/>
                            </xh:tr>
                            <xh:tr>
                                <xh:td>
                                    <fr:number xmlns="http://orbeon.org/oxf/xml/form-builder"
                                               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                               xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
                                               id="integer2-control"
                                               bind="integer2-bind">
                                        <xf:label ref="$form-resources/integer2/label"/>
                                        <xf:hint ref="$form-resources/integer2/hint"/>
                                        <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                    </fr:number>
                                </xh:td>
                                <xh:td/>
                                <xh:td/>
                                <xh:td/>
                            </xh:tr>
                            <xh:tr>
                                <xh:td>
                                    <fr:number xmlns="http://orbeon.org/oxf/xml/form-builder"
                                               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                               xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
                                               id="integer3-control"
                                               bind="integer3-bind">
                                        <xf:label ref="$form-resources/integer3/label"/>
                                        <xf:hint ref="$form-resources/integer3/hint"/>
                                        <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                    </fr:number>
                                </xh:td>
                                <xh:td/>
                                <xh:td/>
                                <xh:td/>
                            </xh:tr>
                            <xh:tr>
                                <xh:td/>
                                <xh:td/>
                                <xh:td/>
                                <xh:td/>
                            </xh:tr>
                            <xh:tr>
                                <xh:td>
                                    <xf:trigger id="save-control" bind="save-bind">
                                        <xf:label ref="$form-resources/save/label"/>
                                        <xf:hint ref="$form-resources/save/hint"/>
                                        <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                    </xf:trigger>
                                </xh:td>
                                <xh:td/>
                                <xh:td/>
                                <xh:td/>
                            </xh:tr>
                            <xh:tr>
                                <xh:td/>
                                <xh:td/>
                                <xh:td/>
                                <xh:td/>
                            </xh:tr>
                            <xh:tr>
                                <xh:td>
                                    <xf:output id="errorCount-control" bind="errorCount-bind">
                                        <xf:label ref="$form-resources/errorCount/label"/>
                                        <xf:hint ref="$form-resources/errorCount/hint"/>
                                        <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                    </xf:output>
                                </xh:td>
                                <xh:td/>
                                <xh:td/>
                                <xh:td/>
                            </xh:tr>
                        </fr:grid>
                    </xf:group>
                </fr:section>
            </fr:body>
            <fr:error-summary observer="error-summary-group" id="error-summary"
                              errors-count-ref="instance('control-instance')/error-count">
            </fr:error-summary>
        </fr:view>
    </xh:body>
</xh:html>
¡I hope you can help me!

Sent from the Orbeon Forms community mailing list mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: Enable / disable button with error-summary

Alessandro  Vernet
Administrator
Hi Ruben,

I imagine this is in a form you're creating in Form Builder, right? Then you
shouldn't need to add the `<fr:error-summary>` "by hand" in the source. Are
you doing so just because you want to access the number of errors? If so,
you can access that value with the following, but this only in actions; if
you're trying to access it in `<xf:bind>`, you're likely to get an
"outdated" count. Would using an action work in your case? If not, could you
tell us more about the use case where you would need this?

xxf:instance('fr-error-summary-instance')/counts/@error

Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Enable / disable button with error-summary

Alessandro  Vernet
Administrator
Hi Ruben,

Have found a solution to this one? Have you maybe tried to access the number
of errors that the "default" error summary keeps track of?

Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Enable / disable button with error-summary

Ruben Garay
Hi Alex!

I still can not find a solution, basically it is required that there are no
errors in the form, if there are no errors a read-only button can be
enabled, this button calls a service.
Could you give me an example of the use of the declaration xxf: instance
('fr-error-summary-instance') / counts / @ error in an action? or Is there
another way to solve this scenario?

I appreciate your help Alex!

--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: Enable / disable button with error-summary

Ruben Garay
In reply to this post by Alessandro Vernet
Hi Alex!

I still can not find a solution, basically it is required that there are no errors in the form, if there are no errors a read-only button can be enabled, this button calls a service.
Could you give me an example of the use of the declaration xxf: instance ('fr-error-summary-instance') / counts / @ error in an action? or Is there another way to solve this scenario?

I appreciate your help Alex!

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: Enable / disable button with error-summary

Alessandro  Vernet
Administrator
Hi Ruben,

Here is an example:  form.xml
<http://discuss.orbeon.com/file/t119778/form.xml>  .

<http://discuss.orbeon.com/file/t119778/Button_shows_when_all_fields_are_valid.gif>

But be careful, because for this to work, I had to replace the `bind` on the
button by `ref`, which might confuse Form Builder. So don't be surprised if
at some point you need to recreate the button. You'll let me know if this
works for you.

Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Enable / disable button with error-summary

Ruben Garay

Perfect Alex!

Thanks to your help, I have solved the problem. I also discovered that I can
use: xxf:instance('fr-error-summary-instance')/visible-counts/@error

Regards!

--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: Enable / disable button with error-summary

Ruben Garay
In reply to this post by Alessandro Vernet
Perfect Alex!

Thanks to your help, I have solved the problem. I also discovered that I can use: xxf: instance ('fr-error-summary-instance') / visible-counts / @ error

Regards!

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: Enable / disable button with error-summary

Alessandro  Vernet
Administrator
Excellent Ruben, and thank you for the update!

Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
--
Sent from: http://discuss.orbeon.com/

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet