How to clear validation messages in a dijit form - javascript

How to clear validation messages in a dijit form (widgets including validation textboxes, filtering selects, number textboxes etc without resetting the form, ie Data need to be retained but validation messages. I am looking for a kind of flush action retaining the data.

You can use the reset function on the form itself.
reset(e) restores all widget values back to their init values, calls
onReset() which can cancel the reset by returning false,. Resource.
Example:
require(["dijit/registry"], function(registry){
var form = registry.byId("yourFormId");
form.reset();
});

registry.byId(textBoxId).reset();

Related

Can't get values from form in a jQuery modal

I'm having a ton of trouble with this form I created on a WordPress site. It uses Gravity Forms, and submissions are handled through AJAX.
The form exists on a modal (using custombox jQuery plugin) which is triggered when you click the "Contact" menu item.
Basically, jQuery events don't work on the form. If you hit submit without filling in the proper fields, the form fails to trigger a validation error message. If the form IS filled out correctly, the entry is saved but no confirmation message is sent.
I've tried handling the validation myself (pasting code below), but I can't get the values of the inputs unless you refresh or hit submit a 2nd time. Upon initial submit, it only returns the initial values, not the new ones.
I have the script loading in the head, and inside a document ready function. I'm completely out of ideas and would really appreciate any help!
$('body').on('submit', '.custombox-content form#gform_1', function(){
console.log('submit');
var inquiry_type = $('.inquiry select').attr('value');
console.log(inquiry_type);
//validateForm();
});
Here, I'm trying to get the value of a select input. When the form is submitted, 'submit' is logged along with the initial select field value. It doesn't log the real selected value until I hit submit a 2nd time.

jQuery change function, how to save the state like a session

I am looking for a way with my form I am currently showing and hiding fields based on the values selected in the dropdowns, What I want to know is.
when i select yes and the field below displays I click submit on the form, if I return to the form the value is still present but the field is hidden again...
How can I prevent that from happening by default?
I want my browser to remember the jQuery change funtions state I left it at after I submit the form.
What you want to do is 'refresh fields visibility' in some cases. I suggest you to create such function refreshFieldsVisibility. Such function reads values from the dropdown and shows/hide the proper field. Then call your function:
When elements state is changed, with on('change') events.
When document is ready (this is your case as I understand), with $(document).ready
Any other situation if necessary

AngularJs - Make form valid manually

I have form with multiple textboxes. If user leaves a field blank he will be shown a checkbox under the form, if the user selects the checkbox then form can be submitted inspite of fields empty.
So for checkbox click, i have to make the form valid manually.
I tried doing form.$valid = true; but doesn't give me proper results.
Have any idea How to make form valid manually.
Angular provides this functionality to you via method on the form object that gets created.
$valid is a boolean, meant to be used as a read-only value.
If you would like to force the form to be valid, use $setValidity
from the documentation:
Change the validity state, and notifies the form when the control changes validity. (i.e. it does not notify form if given validator is already marked as invalid).
This method should be called by validators - i.e. the parser or formatter functions

How to validate a form step-by-step (3 steps) into a carousel?

I need build a form in three steps inside a carousel. I'm using the bootstrap to create the site but I dont know how to validate one step of my form without submit the data and after show the second step (or second slide) to the user continue filling the form up to the third step (or third slide) when he can submit the data. Someone have an idea?
You might just want to validate the fields of the form locally.
You can just bind the onsubmit event listener to the form element, which will be trigger when user submit the data. As you want to validate the form step-by-step, you just need to validate the current step's fields in each step, that you should use event.preventDefault() to stop submitting the data in step one and step two. The code may like:
ndForm.addEventListener('submit', function(e) {
if (!checkSteps()) {
e.preventDefault();
}
});
Or you can validate the field immediately after the user modify it; e.g. attach the onblue event listener to the text field to handle user's input.
I prefer the first way since the code is much clearer and more maintainable.

remove value on field on submit if value is equal to default value?

I have a form that uses a servlet I don't have access to for validation. The powers that be want the field to be prefilled with a value "Enter promotion code" - unfortunately, since placeholder doesn't work with IE, the field is going through the validation process on submit for the default text.
Is there a way to clear the value on that field if the value equals the default text when the form is submitted? (jquery or javascript)
thanks!
You should toss this somewhere on load.
If you aren't using jQuery on the page yet, it'll look like this:
$(function() {
// when the submit button is pressed
$('#yourForm').submit(function() {
if($('#yourInputBox').val() == YOUR_DEFAULT_STRING)
$('#yourInputBox').val(''); // clear the value
return true; // submit the form
});
});
You haven't provided any code to work with, but conceptually you can hook the submit function for your form with javascript, check to see if the prefilled value is still in the form and clear it if so and then allow the submit to proceed.

Categories

Resources