jQWidgets Forums
jQuery UI Widgets › Forums › React › Problem with validator
Tagged: validator react form
This topic contains 3 replies, has 2 voices, and was last updated by assembler 7 years, 6 months ago.
-
AuthorProblem with validator Posts
-
I have a form with two simple text inputs. I’ve placed a validator like this:
<JqxValidator ref={this.validatorRefBuilder} position={'bottom'} hintType={'label'} rules={[ { input: '.descInput', message: 'Desc Required', action: 'blur', rule: 'required' }, { input: '.abInput', message: 'AB Required', action: 'blur', rule: 'required' } ]}> <form id='form' action='./'> ... </form> </JqxValidator>
The problem is every time I load the form it shows me the error on Desc. The Desc field has the
focus()
in the componentDidMount. If I remove the focus method from it, then the validator works as expected. Is this an issue or am I missing something here?Best Regards!
Hi assembler,
I made an example in which when the page is loaded it focuses the first input, but not showing the error(the error shows when I lose the focus of the input, as expected). Check it out and see if it works the same for you.
Here’s the code:class App extends React.Component { componentDidMount() { document.querySelector('.descInput').focus(); } render() { return ( <JqxValidator ref={this.validatorRefBuilder} position={'bottom'} hintType={'label'} rules={[ { input: '.descInput', message: 'Desc Required', action: 'blur', rule: 'required' }, { input: '.abInput', message: 'AB Required', action: 'blur', rule: 'required' } ]}> <form id='form' action='./'> <input className='descInput' /> <input className='abInput' /> </form> </JqxValidator> ); } }
Best Regards,
IvojQWidgets Team
http://www.jqwidgets.com/Mr. Ivo Zhulev,
Thanks for your response. Try your solution withJqxInput
instead ofinput
. Isn’t the same.
Cheers.Mr. Ivo Zhulev,
I just found a solution for this. I’m callingmyJqxInput.focus()
wrapped into asetTimeout
function passing it 100 milliseconds. I guess React is taking some time to load other things in the background.
Best regards. -
AuthorPosts
You must be logged in to reply to this topic.