0
votes

I have dojo validation textbox in my xpage with required property computed (compute dynamically) as below

var syn = getComponent("SynCboxGrp").getValue();
if (syn == "Yes")
{return true;
}else{
    return false;
}

Here the component SynCboxGrp is radio button. The text box is required based on the radio button value. But its not working properly. Changing radio button value doesnt change the required behaviour.

Appreciate any help


Update

Thanks stwissel, Per Henrik Lausten and Eric. I only have this ssjs in required property

<xe:djValidationTextBox id="UBOCAgent"                      value="#{dsRacDoc.UBOCAgent}"                       disableClientSideValidation="true">
<xe:this.required><![CDATA[#{javascript:var syn = getComponent("SynCboxGrp").getValue();

if (syn == "Yes")
{
    return true;
}else{
    return false;
}
}]]></xe:this.required>
</xe:djValidationTextBox>  

I also tried this partial refresh code on my radio button onclick event XSP.partialRefreshGet("#{id:UBOCAgent}");

This still doesnt change the behaviour. It works based on the initial radio button value. On the negative side since its a get request it updates the field content from the server. I also tried Eric's suggestion disable client validation but that didnt help.

Eric, I am also trying to go with CSJS wherever possible but in this case the required property only has the SSJS option. So not sure how to try CSJS. Should i try creating my own dojo field instead of using one from entension lib? If so i am not sure how to compute required property for that. If you can help me with some sample code that would be great help. Thanks for your time.

2
More code please, a full (not) working example. And a server side code doesn't execute on a change in the client side.stwissel
Have you set the radio button to do a partial refresh of the text box (in order for it to re-compute the required property)? As Stephan writes, please add some more of your code to make it easier to answer your questionPer Henrik Lausten
Thanks stwissel, Per Henrik Lausten.lense

2 Answers

1
votes

You're doing a partialRefreshGet, which is updating the Dojo Validation Text Box. But you never post back the updated value from the radio, so the server-side value for the radio button is still the initial value. Consequently, required is still false.

Check the markup when required is true on the Dojo Validation Text Box, but the validation triggers client-side, so there should be an attribute in the markup that you can manipulate via CSJS, if that is your preferred route.

Do you have particular latency issues that you need to work around? Picking up on this and the other question you have about doing a lookup to a database on click of a button, you're hitting a few problems. I don't know how experienced you are in XPages development, but it's not an approach I would recommend without a good understanding of client-side output and server-side component trees. The initial page load of your XPage will also be slower and the size of the HTML passed to the browser will be larger, because of the amount of CSJS passed to the browser.

I would recommend using the in-built partial refresh except for situations where browser to server network is a significant issue, and only then falling back to coding your own partial refresh posting a subset of data. In my experience, it's easier and quicker to develop, easier to debug and more flexible.

For this particular scenario, regardless of whether you code the partial refresh yourself or use inbuilt functionality, one point I'm not certain of is this. That once you set validation on the Dojo Validation Text Box, that validation runs client-side and may impact any attempt to un-set the required property by posting to the server. I haven't tested, so can't be certain.

0
votes

One of two things:

  1. as previously mentioned, to trigger your SSJS value change, ensure a partial (at least) refresh of the element containing your above code; can be done with a container element. Also, check to see if your field's disableClientSideValidation parameter is set (All Properties view).
  2. convert your SSJS code (which merely returns a binary assessment of a Yes or otherwise, I'm assuming No, value) to CSJS

Of late, after the primary development of my current project, I have started favoring the CSJS approach, for the sake of decreasing server-side call backs; most especially in situations where display/rendering of a component is all I'm trying to achieve. If you go this route, remember that dojo.byId("#{id:myControlsServerNameHere}").value (for a text field, see below for scraping a radio button value) combined with setting the display or visible CSS properties can be very handy. As the docs describe, if you want it to exist on the page but not show (for formatting purposes, also, can preserve default value), go the visibility route, otherwise display property.

The CSJS scrape of radio values that I'm currently using is as follows:

var result=null;
for(i=0; i<document.forms[0].elements.length;i++){
    if(document.forms[0].elements[i].name=="#{id:serverNameOfRadioElement}"){
        if(document.forms[0].elements[i].checked == true){
            result=document.forms[0].elements[i].value;
            break;
        }
    }
}
//then handle your result, either with an if, or switch statement

Hope this helps. If there's more you're having trouble with, post back with more code to give the bigger picture.