10440
Views
15
Comments
Solved
Custom validation message for input type="Number" when min attribute is set
Question
Hi EveryOne,

I am using an input with type set to number. In extended properties I have set the min attribute to "1". Now the control is displaying positive numbers starting from 1. But user can enter manually some text into the input.
The input control is inside EditRecord control.

My Problem is when user enters any negative number or zero and clicks submit button then it is displaying the error message as "Integer expected" instead of "Value should be greater than 0".

How to customise that message. Please help me
For reference adding image here





Thanks in Advance.
Solution
Hello Salini and Suraj,

I'm afraid I didn't understand your exact issue initially. Now that I read all the messages in the thread more carefully I was able to make a couple tests on my own and I reached the same situation as you:



In this test, with the property min = 1 set on the inputs, you can see a built-in message "Please select a value that is no less than 1". This message appears as a balloon if the input is inside the Edit Record widget, but appears as a tooltip if it is outside. And it seems that the validation occurs before the logic of the action associated with the button Ok. That is the explanation I can think of why the default message "Integer expected!" also appears, but I think it can be considered a bug.

If I remove the property min = 1 from the inputs, this is the result:



This time, I cannot make a validation on the input outside the Edit Record widget. But for the input inside the Edit Record I was able to define my custom message "IntegerAttribute must be >= 1".

Perhaps you can simply drop the property min = 1, allowing the user to enter something like "0" or "-10" but immediately providing the user feedback about the expected input?

I also attach my small test module in case you want to see it.
Test.oml

Rank: #127
Hi Salini,

You can run javascript code to check what is the number entered in text box.

or at the start of submit action, check what is the value of text in text box. Give one if condition and check whether number is less than 0 and on true branch give feedback message "Value should be greater than 0".

Hope this helps.


-- Suraj B
Rank: #127
Hi Salini,

Please share sample oml file.
Rank: #2020
Hi Suraj,

I am sharing my sample oml, Please go through it and if you need any more explanation then please ask me, i will try to ask my requirement in a clear way thanks.


The thing here is , if i place the input inside edit record then on mouse hover i am getting the required validation, but below the textbox its saying integer expected.

Thanks
MainModule.oml

Rank: #127
Hi Salini,

I have added Javascript code on WebScreen1. This Javascript code will not allow any characters to be entered into it and it will also not allow negative number. (If you want to accept integers as well just change input parametrs at the time of calling Javascript).

I observed that when we click on Ok button and value in the text box is "0", it gives an error "integer expected".

On property window of button, I set "Validation" property to "Server" (earlier it was "Client and Server") and now I am not seeing an error. 

We may need to ask support team why this is happening when it was Client and Server but for now it is working.

(Note : I have tested this oml for OnClick property of button and not for mouse hover)

Regards,
Suraj Borade

MainModule_Modified.oml

Rank: #127
Hi Salini,

If I understand your problem correctly, you don't want "0" at all? I am asking since I din't get last part of your reply. 

If you don't want "0", I think we can customize existing javascript. We need to do something with key value of "0" in javascript.

Let me know if this is your requirement and I will try to modify javascript one more time.

-- Suraj B
Rank: #127
Hi Salini,

To summarize, before inserting into database you want to avoid "0" and you don't want to enter single "0" in textbox as well.

Well, I will need to do some research but before inserting into database you can try attached logic on submit button.

Hope this helps.
temp1.png

Hello Salini,

There's an easier and more direct way of doing this validation, that I think matches exactly what you need. Please see the following two videos from the online training:


In the button that you're using to submit the inputs of the form, you need to change the property Validation to "Client & Server".

Then, in the action associated with the button, you can check the value that the user entered in the input, perform your validations, and if the value is invalid you assign <Input>.Valid = True and <Input>.Message = <Your custom message>.

Finally, at the end of all your validations, you just need to check if <Form>.Valid is True or False. If it is False, you end your action there (meaning that the application does not advance to another screen). Your custom message is displayed next to the invalid input.
Rank: #127
Hi Paulo,

Thanks for the inputs. But we are still not getting why "Integer Expected" error is coming?

Can you please look at the oml one more time?

Thanks,
Suraj B
Solution
Hello Salini and Suraj,

I'm afraid I didn't understand your exact issue initially. Now that I read all the messages in the thread more carefully I was able to make a couple tests on my own and I reached the same situation as you:



In this test, with the property min = 1 set on the inputs, you can see a built-in message "Please select a value that is no less than 1". This message appears as a balloon if the input is inside the Edit Record widget, but appears as a tooltip if it is outside. And it seems that the validation occurs before the logic of the action associated with the button Ok. That is the explanation I can think of why the default message "Integer expected!" also appears, but I think it can be considered a bug.

If I remove the property min = 1 from the inputs, this is the result:



This time, I cannot make a validation on the input outside the Edit Record widget. But for the input inside the Edit Record I was able to define my custom message "IntegerAttribute must be >= 1".

Perhaps you can simply drop the property min = 1, allowing the user to enter something like "0" or "-10" but immediately providing the user feedback about the expected input?

I also attach my small test module in case you want to see it.
Test.oml

Rank: #68498

click in the app