Jump to content

Check Textbox "Confirm" value


Recommended Posts

Hi, I have a textbox with an associated "Confirm" textbox. If the values in both boxes don't match, I want a mechanism to immediately inform the user and not have to wait until the submit button is clicked.

image.png.fa35b8e87af9ad7472705e873853fcb0.png

I've tried, using a virtual calculated value box with:-

CASE
WHEN CAST([@field:Barcode_ID] AS String) = CAST([@field:Barcode_ID@Confirm] AS String) THEN "Barcode is valid"
ELSE "Barcode is Invalid"
END

I get an error after clicking "Verify Formula". The error is "Type String is not a defined system type. Invalid column name '@field:Barcode_ID@Confirm'." The entry could be alpha numeric that's why I've tried using "String".

I've tried using Calculated Value but if a javascript solution with an "alert" is available then I'd prefer to use that.

Your help would be greatly appreciated.

 

Link to comment
Share on other sites

Hi, I've turned to JS to try to solve this but it's still not giving me a result. Here's the code I'm working with:-

<script type="text/javascript">
    var pwd = document.getElementById('Barcode_ID');
    var pwdc = document.getElementById('InsertRecordBarcode_ID@Confirm'); 
    if(pwdc.value <> pwdc.value}{alert "Error"}
</script>

I've placed this code in the footer with the HTML editor disabled. If you can spot where I'm going wrong, I'd be really grateful if you could let me know.

Cheers, Ron

Link to comment
Share on other sites

23 hours ago, RonAnderson said:

Hi, I have a textbox with an associated "Confirm" textbox. If the values in both boxes don't match, I want a mechanism to immediately inform the user and not have to wait until the submit button is clicked.

image.png.fa35b8e87af9ad7472705e873853fcb0.png

I've tried, using a virtual calculated value box with:-

CASE
WHEN CAST([@field:Barcode_ID] AS String) = CAST([@field:Barcode_ID@Confirm] AS String) THEN "Barcode is valid"
ELSE "Barcode is Invalid"
END

I get an error after clicking "Verify Formula". The error is "Type String is not a defined system type. Invalid column name '@field:Barcode_ID@Confirm'." The entry could be alpha numeric that's why I've tried using "String".

I've tried using Calculated Value but if a javascript solution with an "alert" is available then I'd prefer to use that.

Your help would be greatly appreciated.

 

Hi @RonAnderson,

For this formula, you can use a Virtual field instead of a confirmation textbox. 

CASE
WHEN [@field:Barcode_ID] = '' OR '[@cbParamVirtual1]' = '' THEN ''
WHEN [@field:Barcode_ID] = '[@cbParamVirtual1]' THEN "Barcode is valid"
ELSE "Barcode is Invalid"
END

 

The reason why you got an error is because of the confirmation field [@field:Barcode_ID@Confirm].  If you will check the picker button, this field is not available. Thus, you cannot use it in the formula. 

Link to comment
Share on other sites

4 hours ago, RonAnderson said:

Hi, I've turned to JS to try to solve this but it's still not giving me a result. Here's the code I'm working with:-

<script type="text/javascript">
    var pwd = document.getElementById('Barcode_ID');
    var pwdc = document.getElementById('InsertRecordBarcode_ID@Confirm'); 
    if(pwdc.value <> pwdc.value}{alert "Error"}
</script>

I've placed this code in the footer with the HTML editor disabled. If you can spot where I'm going wrong, I'd be really grateful if you could let me know.

Cheers, Ron

Hi @RonAnderson

Here's the JavaScript solution as well:

<script type="text/javascript">
document.addEventListener('DataPageReady', onChangeFunction)

function onChangeFunction() {
   document.getElementById("InsertRecordBarcode_ID").addEventListener('change', Alert); 
   document.getElementById("cbParamVirtual1").addEventListener('change', Alert); 
   document.removeEventListener('DataPageReady', onChangeFunction)
}

  var x = document.querySelector('[id*=InsertRecordBarcode_ID]');
  var y = document.querySelector('[id*=cbParamVirtual1]');

function Alert(event) {
    if (x.value != y.value && x.value != '' && y.value !='')
    alert("Barcode is Invalid");
}

</script>

You may paste this in the Footer of the DataPage. 

 

Hope this helps :) 

Link to comment
Share on other sites

On 7/23/2023 at 11:24 AM, RonAnderson said:

Hi @cheonsa This worked for me, thank you so much. However, I actually want the alert message to show if the two values differ. I tried:-

if (x.value !<> y.value && x.value !<> '' && y.value !='')

but it failed. Could you help me that last step and amend the code? I'm a rookie when it comes to JS.

Best regards, Ron

Hi @RonAnderson

It's good to know that it works for you. 

Based on this condition, the alert message will prompt if the value of x and y is not equal. I just added that x and y should not be blank so it will not be displayed upon loading the DataPage.

if (x.value != y.value && x.value != '' && y.value !='')

May I know what is the actual result on your end?

Link to comment
Share on other sites

Hi @cheonsa Again, thanks for your response. I did as instructed and replaced the line of code which you kindly provided. Unfortunately, I get the "Barcode is invalid" if the entries match or not.

image.thumb.png.350cd16aef7110e7a1a5289a5427a3d5.png

Here's the code I'm working with:-

image.png.dcba643e18a4b33548777cbe8fab5677.png

I don't know JS very well so I can't assess if I've done something wrong or accidentally skewed the code. Could you review and let me know please.

Thanks again, Ron

Link to comment
Share on other sites

Hi @RonAnderson,

 

Below you may find a sample code that should work with the main "Repeat for confirmation" feature and without using Virtual Fields. The alert will trigger only when the fields have mismatching data in them, and not when either or both of them are empty.

 

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {

document.querySelector("[id='InsertRecordBarcode_ID']").addEventListener('change',ShowAlert);
document.querySelector("[id='InsertRecordBarcode_ID@Confirm']").addEventListener('change',ShowAlert);

function ShowAlert() {
var field = document.querySelector("[id='InsertRecordBarcode_ID']").value;
var confirm_field = document.querySelector("[id='InsertRecordBarcode_ID@Confirm']").value;
if (field && confirm_field) { 
     if (field != confirm_field) { alert("Text does not match") }
}

}

});
</script>

 

Link to comment
Share on other sites

  • 3 weeks later...

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
Reply to this topic...

×   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...
×
×
  • Create New...