Note that there are some explanatory texts on larger screens.

plurals
  1. POServer Side Validation - computing the required parameter to a viewScope
    text
    copied!<p>I'm having an issue with some server side validation and I can't tell if this is the expected behavior in XPages or if I'm missing something simple here.</p> <p>I have a field that has a computed validation formula - basically, it becomes required when a viewScope variable gets set.</p> <p>My submit button sets the viewScope and does a full refresh.</p> <p>I would expect the form to be submitted, the validation formula gets evaluated, and if it fails the validation failure would be displayed. But when I click my submit button the form is submitted without error. If I click it again, validation fails as expected.</p> <p>To illustrate my issue I created a simple example:</p> <p> </p> <pre><code>&lt;xp:inputText id="inputText1" required="#{javascript:viewScope.validate}"&gt; &lt;xp:this.validators&gt; &lt;xp:validateRequired message="This field is required."&gt;&lt;/xp:validateRequired&gt; &lt;/xp:this.validators&gt; &lt;/xp:inputText&gt; &amp;#160; &lt;xp:button value="Submit" id="button1"&gt; &lt;xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="true"&gt; &lt;xp:this.action&gt;&lt;![CDATA[#{javascript:viewScope.validate=true;}]]&gt;&lt;/xp:this.action&gt; &lt;xp:this.script&gt;&lt;![CDATA[dojo.attr(dojo.byId("#{id:inputText1}"),"aria-required","true")]]&gt;&lt;/xp:this.script&gt; &lt;/xp:eventHandler&gt; &lt;/xp:button&gt; &lt;xp:br&gt;&lt;/xp:br&gt; &lt;xp:message id="message1" for="inputText1"&gt;&lt;/xp:message&gt; </code></pre> <p></p> <p>As you can see, I also tried adding the aria-required attribute with csjs within the button in the hopes it would initiate validation.</p> <p>If validation is working as expected are there any suggestions for getting dynamic validation like this to function properly? I know I can do something with querySave on the data source (I excluded a data source from the example for simplicity) but was hoping there is a simpler solution than that. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload