Have a chat room, issue is, is that when you submit something, the message in the form box stays. What I want, is for when it is submitted using the button, the message one clears.
So, I added $('#mbody').val(''); and added the id mbody to the form with the message in it. But for some reason, it clears the other form.
You don't need to change the non-existant value of the FORM (form inputs have values). You simply need to reset it.
var form = document.getElementById('mbody');
form.reset();
Make sure each form has a unique id.
I'll see your vague question lacking example code and raise you a vague answer. ID's need to be unique - you likely have duplicate ID's or are referencing the incorrect ID.
Related
Very weird thing that Formik seems to be so famous but I can't find this very simple functionnality.
Lets say the user try to send the form with an empty field, how can I display the errors ? I can display them once the field is touched but not once the form has been sent (and obviously I don't want to display the errors right away, for example an empty field)
The actual behavior is that the submit function is not called if the validation fails, seems right but what about error display ? It seems there is no simple way to do this (I found a few kinda heavy work around with some callbacks and handler components but what's the point using a form library then...)
So maybe I have missed something please tell me
Any idea how to display the validation errors when submitting the form ?
I have several inputs and a button. I want to do something on button click, but before I need to validate inputed data. If data is incorrect, app should highlight inputs and show a message.
What is "canonical" way to do it?
Short answer: there's no convention.
You can roll with any validation library you choose, so as long as you can hook it up, show invalid input errors, as well as prevent the form from submitting if the form is invalid.
I'm sure this has come up many, many times before but I am at my wit's end with this problem. I'll try and be as descriptive as possible without bloating the problem statement.
I am using the jQuery validate plugin for form validation. All form rules and messages are retrieved via ajax and then initialised. All form validation works like a charm until I start cloning fieldsets inside the form to give the user the ability to add additional entries.
The input fields react exactly as they should to changing values (error highlights and displaying messages etc), but when I call the .valid() method on the form it ignores the additional fieldset cloned from the first.
I have added test rules after cloning the fieldset, and again, the input field responds correctly to the newly assigned rule but gets ignored when calling .valid() on the form element.
I will add code snippets should anyone be willing to help me find the problem.
Thanks in advance!
Fred
Edit:
I have found that the .valid() method only uses the first fieldset in the form. Take note that all input names of cloned fieldsets are the same as the original. For example, say i have a field called productName in my original fieldset and i clone it, I will now have two inputs in the form with the same name attribute.
Could it be that jQuery validate only cares about the first instance it reaches and validates on that? I have seen posts about jQuery validate not playing nice with duplicate input names on forms but i believe it was resolved.
On an EWF page, is it possible to alter the content of a form item during validation (when a validation fails)? For an example: say you have a text box that you want to be spell checked before it gets entered into the database. You use the modification's GetSpellCheckedWordTextFormItem to get the form item, and you want to replace what the user enters ("teh") with a likely suggestion ("the") when the validation fails to find a word it knows. Then the user sees the validation error ("Is this the word you meant?"), looks at it and corrects it or not, then re-submits.
Is there a way to do that? If so, how?
The specific answer to your question is no, you can't alter any form values if validation fails. To implement this, you'd need to let the validation succeed and let the data get modified. As part of the validation/modification, you could set a piece of page state that causes the next loadData pass to display the "is this the word you meant?" message near the spell-checked form item. Of course, you would have already saved the corrected text.
Alternatively, you could use PostBack.CreateIntermediate to make a post-back that only runs the spell-check, puts the corrected text in page state, and displays "is this the word you meant?". You'd set that post-back to fire when the user tabs out of the text box, and then you'd have the main post-back grab the corrected text from page state and save it in the database or other durable storage.
I have used webshims for html5 form validation in a single page app with multiple pagelets(divs). The forms are not submitted but local javascript is invoked after each conversation and collected data is posted .
Next I iterate over all the fields and reset the values.
Then I take the new user back to the first pagelet having first form for the new conversation. This time even after filling the correct values the border does not turn green.
Note:
However when we select the field and click outside the field without filling it. and then after filling the correct data border turns green.
However when we tried to achieve it programmatically iterating over each field resetting it and using javascript focus method, that did not do the trick.
I am sure I must be missing some thing. would be able to point out what.
Regards
Barman
I'm not sure, what you want to achieve. I would need to see some code. If you change the value programmatically you can update the validation ui with the event refreshvalidityui on the form field. If you want to reset the ui, you can either trigger a reset event on the form or resetvalidityui on the form field
$('input').val('foo').trigger('refreshvalidityui');
or
$('input').val('foo').trigger('resetvalidityui');
or
$('form').trigger('reset');
Please let me know, if this helps.