Hello,
Is there way to set to specific RegExpTextBoxSetting IsValid true or false in runtime myself?
I want to see the error message of the RegExpTextBoxSetting in specific cases.
Is it possible? or the RegExpTextBoxSetting display the error message only by the regular expression ?
Thanks.
7 Answers, 1 is accepted
You can wire the client side event OnValidating of the RegExpTextBox setting and perform your custom check there. If you decide that the value is invalid, you can use the following code:
function
validating(sender, eventArgs) {
var
tb = $find(
"<%= RadInputManager1.ClientID %>"
).get_targetInput(
"<%= TextBox1.ClientID %>"
);
//perform your custom check
if
(tb.get_value().indexOf(
'9'
) < 0) {
tb.get_owner()._inputs[tb._id]._invalid =
true
;
tb.updateCssClass();
e.preventDefault();
}
I hope this helps.
Greetings,
Tsvetina
the Telerik team
in addition, there is no preventDefault method to the eventArgs !
You could try by setting the text manually, using set_value() method on the textbox.
As for the preventDefault(), firstly, please note that I had a name mismatch in my code, as my event arguments are declared first as eventArgs, then I call the method on e. Apart from that, preventDefault() is a javascript method that is always applicable on cancellable events, and OnValidating is such, so it should be available for you to call.
Kind regards,
Tsvetina
the Telerik team
I'd like to share whith our code so maybe u will be able to point where the problem is.
We are creating a custom control for regular expression, and now we created custom control for identity. validation of identity we check in JS function we have built so we needed that the valid of our control will be changed against the return value of our function.
We use textbox. refexptextboxsetting. targetinput and radinputmanager.
we add the regexp :
regExpTextBoxSetting.ClientEvents.OnValidating = REG_EXP_ON_VALIDATING_EVENT_HANDLER;
//consts of the name of functionand then in global func which adds the script to the creation of the control we have written:
function validating(sender, args) {
var tb = $find('"
+ radInputManagerClientId + @"').get_targetInput('" + textBoxClientId + @"');
//perform your custom check
txtIdentity = document.getElementById('"
+ textBoxClientId + @"');
var retVal=ValidateTZ(txtIdentity.value);
if(retVal==false){
tb.get_owner()._inputs[tb._id]._invalid = true;
tb.updateCssClass();
args.preventDefault();
}
}
errors:
1. args-doesnt have the methos preventdefault.
2. we see no change of the control. even if the ret value was false.
thanks a lot!
Even if you do not use the preventDefault() method, if you manage to get hold of the RadInputManager and the textbox that it validated, you should still be able to set the invalid style to the textbox. I am attaching a sample application demonstrating that. Please, make sure that you get the correct reference to your RadInputManager.
Best wishes,
Tsvetina
the Telerik team
thanks for your answer, but actually i don't see any change between the solution u have sent me to the code i have written in the previous reply.
When running in debug, i get in the last if statement, and see how it puts invalid to my radinput manager, but nothing happens on screen.
thanks for any help,
gila.
The project which I attached does apply the invalid style visually on the textbox on my side. Could you please run the project as it is and see how it behaves? If it works on your side, too, try to make the needed modifications in order for it to start replicating the issue which you encounter and send the full source back to us, so we can see what causes the issue on your side.
Another option would be to open a formal support ticket and send a runnable version of your project for us to debug locally and make the needed changes, so that it behaves as expected.
Best wishes,
Tsvetina
the Telerik team