Jump to content
  • 0

disable checkbox after being checked


DRAhmed
 Share

Question

is there a way to make a checkbox uncheck-able after being checked 

i tried using a virtual field and a disable rule but in this case the check doesn't get registered at all 

after checking the box , it should be uncheck-able but still register in the table 

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 1

Hi @DRAhmed,

You can use the following script:

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
    const selectElement = document.querySelector('#InsertRecordYesNo');

selectElement.addEventListener('change', (event) => {
if(selectElement.checked = true){
document.querySelector("#InsertRecordYesNo").disabled = true;
}
});


});
</script>

 

Make sure to change "YesNo" in "InsertRecordYesNo" to your actual Yes/No field name. 

One question though. What if the checkbox is checked to begin with?

Link to comment
Share on other sites

  • 1
9 hours ago, DRAhmed said:

when i do like that 

the check doesnt get registered in the source table

Yes, because fields that are disabled by Rules tends to not get submitted. What you can do is this:

Create a Virtual field that will act as your Checkbox.
Make your Actual Yes/No field's form element as Calculated Value and make it hidden(Advanced tab)
Use a CASE statement to get the value from the Virtual field:
CASE WHEN [@cbParamVirtual1] = 'Y' THEN CAST('1' AS BIT) ELSE CAST('0' AS BIT) END

Then use the suggestion of @futurist to disable the Virtual checkbox. DO NOT include the actual Yes/No field in the section that you are going to disable. It should only contain the virtual checkbox.

Link to comment
Share on other sites

  • 1
9 hours ago, DRAhmed said:

i did like you said but i recieve 

Values in one or more fields are invalid.

Oh, unhide the calculated value and check if it is getting any value. it might be getting NULL. if yes, try using single quotes for the virtual field.
CASE WHEN '[@cbParamVirtual1]' = 'Y' THEN CAST('1' AS BIT) ELSE CAST('0' AS BIT) END

Or check your virtual field's "value when checked" and see if you have Y there. You might have a different value than what I use.

 

Link to comment
Share on other sites

  • 0
On 10/12/2022 at 11:32 PM, futurist said:

Just to add to this, you can actually do this using Rules.

You can put your Yes/No field in its own section,

image.png.29936b1d0affb8341eb0760f6ec0d9ac.png

 

So that when you set up the Rule, you use the Yes/No field for the criteria, but use its section for the action:
image.png.8b7b525fa7738b69d1b9830deda2200a.png

when i do like that 

the check doesnt get registered in the source table

Link to comment
Share on other sites

  • 0
On 10/16/2022 at 12:24 AM, Tubby said:

Yes, because fields that are disabled by Rules tends to not get submitted. What you can do is this:

Create a Virtual field that will act as your Checkbox.
Make your Actual Yes/No field's form element as Calculated Value and make it hidden(Advanced tab)
Use a CASE statement to get the value from the Virtual field:
CASE WHEN [@cbParamVirtual1] = 'Y' THEN CAST('1' AS BIT) ELSE CAST('0' AS BIT) END

Then use the suggestion of @futurist to disable the Virtual checkbox. DO NOT include the actual Yes/No field in the section that you are going to disable. It should only contain the virtual checkbox.

i did like you said but i recieve 

Values in one or more fields are invalid.

Link to comment
Share on other sites

  • 0
7 hours ago, Tubby said:

Oh, unhide the calculated value and check if it is getting any value. it might be getting NULL. if yes, try using single quotes for the virtual field.
CASE WHEN '[@cbParamVirtual1]' = 'Y' THEN CAST('1' AS BIT) ELSE CAST('0' AS BIT) END

Or check your virtual field's "value when checked" and see if you have Y there. You might have a different value than what I use.

 

i did like this , CASE WHEN '[@cbParamVirtual1]' = 'Y' THEN CAST('1' AS BIT) ELSE CAST('0' AS BIT) END

it worked but it still didnt register in the table

Link to comment
Share on other sites

  • 0
On 10/18/2022 at 7:43 PM, DRAhmed said:

i did like this , CASE WHEN '[@cbParamVirtual1]' = 'Y' THEN CAST('1' AS BIT) ELSE CAST('0' AS BIT) END

it worked but it still didnt register in the table

By it worked but didnt register in the table, do you mean that when you unhid the actual field and tested if the check from the virtual field is getting cascaded, it did, but it did not save upon submission?

Did you put the Virtual field in a separate section as I mentioned? Basically what I had in mind is something like this:

Section 2
VirtualField (Checkbox)

Section 3
Yes/NoField(Calculated Value)

Link to comment
Share on other sites

  • 0
On 10/20/2022 at 5:35 PM, Tubby said:

By it worked but didnt register in the table, do you mean that when you unhid the actual field and tested if the check from the virtual field is getting cascaded, it did, but it did not save upon submission?

Did you put the Virtual field in a separate section as I mentioned? Basically what I had in mind is something like this:

Section 2
VirtualField (Checkbox)

Section 3
Yes/NoField(Calculated Value)

so i tested some things and here is what i found 

everything works 

1) if the virtual field has a rule of getting disabled when checked , the calculated value results in yes but doesnt get saved upon submission 

2) if i remove the rule , it gets saved but this isn't what i want 

Link to comment
Share on other sites

  • 0
On 10/22/2022 at 1:19 AM, DRAhmed said:

so i tested some things and here is what i found 

everything works 

1) if the virtual field has a rule of getting disabled when checked , the calculated value results in yes but doesnt get saved upon submission 

2) if i remove the rule , it gets saved but this isn't what i want 

Sorry, yes I tried creating it back and it isnt working. Not sure what went wrong as this is a known workaround of mine. I don't know what else to try. Maybe anyone else has some other workarounds.

Link to comment
Share on other sites

  • 0
On 10/26/2022 at 1:34 AM, Tubby said:

Sorry, yes I tried creating it back and it isnt working. Not sure what went wrong as this is a known workaround of mine. I don't know what else to try. Maybe anyone else has some other workarounds.

thank you very much for trying

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...