0

I am using Symfony in front-end and I don't know how to control actions inside it dynamically. I mean for example I would like that the browser tell me I am not writing a number in a field called code. Some people told me that javascript resolve this problems, but I do not know how to do that. Do you have an example using pure javascript inside Symfony (with no external libraries please)? The only external library that I am using is JQuery in order to do some actions with AJAX.

Thank you in advance.

6
  • Can you tell me what you're doing? What you have tried for now? Commented Aug 8, 2017 at 18:31
  • 1
    @felipsmartins I think the OP wants to do client side form validation with JavaScript. Commented Aug 8, 2017 at 18:31
  • @felipsmartin, I am using Symfony3.2. I am using forms like it is used in the documentation. So my file xxx.html.twig I got a thing like this: form_label(form.code, code) form_widget(form.code, attr{form_control}) and form_errors. But my problem is that I got the errors when I send the form. I want to get it when I typing (for example if I type a string in the field code I should got an error). Thanks Commented Aug 8, 2017 at 18:41
  • Symfony=PHP=Back-end. JavaScript=Browser=Front-end. Commented Aug 8, 2017 at 19:46
  • I am using Symfony in front-end. That's not my choice . Commented Aug 8, 2017 at 19:55

1 Answer 1

1

you can use a data validator for your form input. Take a look on this link Parsley

To use it, it looks like this :

<form data-validate="Parsley" method="POST">
  <label>my code </label>
  <input data-type="integer" ...>
</form>
Sign up to request clarification or add additional context in comments.

3 Comments

Unfortunatly, I could not use external libraries. I could use only jQuery.
While informing the question OP of this library may be beneficial, the question explicitly asks for a pure JavaScript example without the use of external libraries. Thus, this does not actually answer the question. Also note that using integer is not that great a choice as an example, because that can largely be done in HTML with <input type="number">.
If providing a JavaScript/HTML/CSS answer, you should seriously consider using a snippet. Using a snippet makes it more likely for your answer to be up-voted, because the functionality of your code can be quickly verify, and it tends to more strongly engage readers. While snippets shouldn't always be used, for JavaScript/HTML/CSS based questions and answers, they can significantly improve communicating both the problem and solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.