I thought I understood how to enable and disable buttons with JavaScript. But, something is going on I can't figure out. I have a simple form with a "Disposition" dropdown with six possible choices (plus null) loaded from a static entity. If the selected disposition is final (four choices qualify) I want to enable the Submit button. If the selected disposition is not final (two choices and null) I want to disable the Submit button.

Here is the code I placed in the Value of the 'onchange' property of the Extended Properties of the dropdown. The name of the 'Save and Submit' button is btnSaveAndSubmit.

-----------------------
If(

DeliverableApprovalsForm.Record.DeliverableApprovals.Status = Entities.Disposition.Deferred

Or

DeliverableApprovalsForm.Record.DeliverableApprovals.Status = Entities.Disposition.Recommended

Or

DeliverableApprovalsForm.Record.DeliverableApprovals.Status = Entities.Disposition.Rejected

Or

DeliverableApprovalsForm.Record.DeliverableApprovals.Status = Entities.Disposition.Approved,

"$('#" + btnSaveAndSubmit.ID + "').attr('disabled', false);",

"$('#" + btnSaveAndSubmit.ID + "').attr('disabled', true);"

)

-----------------------

For the sake of simpler discussion let me summarize the above statement as:

If(condition, disabled=false, disabled=true)

When the screen opens, Disposition is 'Pending', making the button disabled. Any selection leaves the button disabled, which is incorrect behavior. The button should become enabled upon selecting Deferred, Recommended, Rejected, or Approved. To test my syntax I changed the above statement to If(condition, disabled=false, disabled=false). On the first change of the dropdown the 'Save and Submit' button became enabled, confirming the onchange was being read and my button ID and syntax were correct.

Therefore, the condition statement must be at fault. The variable property of my dropdown is:

DeliverableApprovalsForm.Record.DeliverableApprovals.Status.

If the above does not work, how do you read a form widget during the onchange event?



Solution

Hi Bill,

you don't js to do this. what you need is to put that rule on the button enabled property and on the dropdown onchange

add an action that should only do an ajax refresh to the submit button.

regards,

Marcelo

Solution

Bill Adams wrote:

I thought I understood how to enable and disable buttons with JavaScript. But, something is going on I can't figure out. I have a simple form with a "Disposition" dropdown with six possible choices (plus null) loaded from a static entity. If the selected disposition is final (four choices qualify) I want to enable the Submit button. If the selected disposition is not final (two choices and null) I want to disable the Submit button.

Here is the code I placed in the Value of the 'onchange' property of the Extended Properties of the dropdown. The name of the 'Save and Submit' button is btnSaveAndSubmit.

-----------------------
If(

DeliverableApprovalsForm.Record.DeliverableApprovals.Status = Entities.Disposition.Deferred

Or

DeliverableApprovalsForm.Record.DeliverableApprovals.Status = Entities.Disposition.Recommended

Or

DeliverableApprovalsForm.Record.DeliverableApprovals.Status = Entities.Disposition.Rejected

Or

DeliverableApprovalsForm.Record.DeliverableApprovals.Status = Entities.Disposition.Approved,

"$('#" + btnSaveAndSubmit.ID + "').attr('disabled', false);",

"$('#" + btnSaveAndSubmit.ID + "').attr('disabled', true);"

)

-----------------------

For the sake of simpler discussion let me summarize the above statement as:

If(condition, disabled=false, disabled=true)

When the screen opens, Disposition is 'Pending', making the button disabled. Any selection leaves the button disabled, which is incorrect behavior. The button should become enabled upon selecting Deferred, Recommended, Rejected, or Approved. To test my syntax I changed the above statement to If(condition, disabled=false, disabled=false). On the first change of the dropdown the 'Save and Submit' button became enabled, confirming the onchange was being read and my button ID and syntax were correct.

Therefore, the condition statement must be at fault. The variable property of my dropdown is:

DeliverableApprovalsForm.Record.DeliverableApprovals.Status.

If the above does not work, how do you read a form widget during the onchange event?



Hi Bill Adams!

As exemple you need to create a screen with a preparation and put a combo box / dropdown inside a form and a button "Save And Submit" on the screen and 2 tables (Disposition table and OtherTable).


2-Drag disposition table and drop it inside of your preparation.

3-Drag table1 table and drop it inside of your preparation.

4-In form:

Select GetTable1s.List.Current as Source Record.




In your Combo Box/Dropdown List:


Select GetDispositions.List as source Record List, Disposition.Label as Source Attribute and in the Onchange Action create select "New Action". It will create na Action with name "OnChange". 

In Your button:

Type the name as "SaveSubmit" and inside of the button Enabled Property put this condition:




In the "OnChange" Action:

Put an ajax refresh widget.



As you can see:

When option is Pending, button is disabled.


When other option is set, button "Save and Submit" is enabled.





I hope it will helps you!


Thanks and Best Regards,

Nuno Pereira




Thank you both. Marcelo for the solution and Nuno Goncalo for all the details to execute it.


Works beautifully, and so much simpler than Java Script!