Enable and Disable Buttons Conditionally


Userlevel 4
Badge +10

I want to enable and disable buttons conditionally with form rules. Below is a screenshot of what I thought would work.

It the item is not signed (empty or null value in the PMApprover control), then I do not want the user to be able to click the submit button. As soon as the PMApprover control has data in it, I want the "Submit" button to light up.

Here is what is happening: When the form is opened, the PMApprover control is null and the submit button is disabled. This is expected.  When I click sign, the PMApprover control and the date control are populated but the button does not enable. The PMApprover control is connected top the list field "PM Approver". I have tried evaluating from the contents of the PMApprover control and the PM Approver list column without success.

Can anyone help?

193311_pastedImage_1.png

Thanks and Regards,

Patrick Kelligan


10 replies

Userlevel 5
Badge +14

you have to base your rule on control's value since field's value is only populated after you submit the form.

regarding of problem with the rule, can you post how do you set up PMApprover's value and what's its datatype?

Badge +9

I too had a similar issue with text box column but it worked in case of dropdown, I guess this is due to the fact that rule is applied at the first page load and after entering value in "PM Approver" the page doesn't refresh due to which the rule remains .Can u try adding validation rule to "Submit" to give error message when "PM Approver" is blank

Userlevel 4
Badge +10

Yes, I first set the condition against the list field and then it came to me that this would not work until after update of the list item. I then worked it against the control and still it did not work.

The PMApprover control is a text box

Userlevel 4
Badge +10

Hi aditya,

I checked it out and mine is behaving the same way. If I set condition against the drop down choice just above PMApprover (PMApproval), it works but I need to validate that a signature is loaded. I will try the validation rule on the submit button.

Thanks!

Userlevel 5
Badge +14

ok.

then try to add to your javascript setter call like

NWF$('#' + PMApprover).focusout();
Userlevel 4
Badge +10

Hi Marian,

I think your code line is working but now when I click the button, the page fully refreshes. Is that an expected behavior or is there a glitch in my code?

Thanks,

Patrick

//=============================;
//  PM Controls;
//=============================;

function signFormPM() {
    var curDate = new Date();
    NWF$('#'+ jsvar_PMDate).val((curDate.getMonth() + 1) + '/' + curDate.getDate() + '/' + curDate.getFullYear());
    NWF$('#'+ jsvar_PMName).val(NWF$('#'+ jsvar_CurUserPreferredName_CAL).val() +" (Current User)");
    NWF$('#' + PMApprover).focusout();
}
//----------------------------------------------------;
function resetSignaturePM() {
    NWF$('#'+ jsvar_PMAction).val("Please select an outcome...");
    NWF$('#'+ jsvar_PMDate).val("");
    NWF$('#'+ jsvar_PMName).val("");
    NWF$('#'+ jsvar_PMComment).val("");
    NWF$('#' + PMApprover).focusout();
}
Userlevel 4
Badge +10

Hi aditya,

I was able to get some validation going on the control but is seems a little awkward and setting up multiple conditions is giving me headaches.

Thanks,

Patrick

Userlevel 5
Badge +14

no, it shouldn't refresh.

haven't we discussed the same issue in some other thread? wasn't it one with disabled control that caused js variable was not defined?

so is PMApprover (or any of other referenced variables) valid variable within the scope of the code?

Userlevel 4
Badge +10

Yes... whenever thee is an error in my code, the page refreshes when the function is called.

Userlevel 4
Badge +10

Hi ‌,

I struggled with the formatting, which I think is a more elegant solution, but I finally settled for validation to force my users to sign before submitting.

Thanks!

Patrick

Reply