Use browser form validation without submission (JS / Jquery) - javascript

I am working on a multi part form that is composed of three views.
The user will have to fill the first part, click next, fill the second part, next again, the third part and finally submit the form.
However I would like to add validation to each part to ensure the user have filled all required fields before reaching the next part.
For simplicity and consistency with the rest of the website I would like to use the browser validation system, which is triggered at form submission by default.
Is there any way to use callback that detect invalid fields and highlight them when the form is submitted without a call to submit ?

Related

How to disable submit in AngularJS in following scenario?

I am having some trouble with disabling Submit button in a HTML form in AngularJS.
Scenario:
I am selecting a certain process from a HTML Select Box ie. Drop
Down List
Once I select some entry from that, the lower portion is
automatically populated with the required form which again has a set
of inputs
Once you fill in these value, you can either Submit or Cancel the request
Condition:
There is a process in the list where I need to upload 1 or more files along with other input parameters. To do this, I am using a two step approach where I first Choose a File using a button and then I use another button to Upload the file. Clicking on this button makes a REST call and the file is sent to the required target.
I am using ng-file-upload directive from https://github.com/danialfarid/ng-file-upload to accomplish this.
Problem:
I was initially using ng-disabledto disable submit button on the condition that All mandatory input elements are filled and all input validations are passed. Now the problem occurs when I am in the use cases which need files to be uploaded. When I choose a file and upload it, HTML treats that element as empty as the file is already sent to its target and hence fails the validation All mandatory input elements are filled! If I remove this validation, my form expectedly get submitted even if Mandatory fields are empty.
So what can I do in this case to disable my submit button?
Create a boolean variable as what #ShashankVivek said.
if file uploaded $scope.uploaded = true.
so your button should look like this
<button data-ng-disabled="!form.valid && !uploaded">Submit</button>

adobe livecycle Message box displayed separately not in a single box

I am using Adobe Livecycle ES2. My code is fine but all my validations are being displayed as a list in one single message box and that's not what I want. I want them to display after the user leave each field that's being validated. I tried solution like File>Form Properties> Form Validation but I don't have the Form validation option. I am wondering if I can get it to work by javascript coding.
You can add field-specific JavaScript code to the exit event for each field. If the user enters a value that doesn't pass the validation, you can then script something (a messagebox, an alert popup or some text) to appear as the user tries to leave the field.
You may want to use softer coded validation (which warns the user that the field isn't correctly completed but still allows them to move elsewhere in the form) in the exit event and use harder/stricter validation at the end of the form, for example, before the form is submitted) so that the user can't submit the form without completing the necessary fields but they can still progress with later fields even if the earlier fields aren't complete.

AngularJS - Form validation except fields that only have the "required" rule

I know with a form, I can get the $valid property to check whether the entire form is valid. Is there a way to get the validity of a form but ignore undirtied fields whose only rule is "required"?
I have a form that has a save button and a next button. This form is part of a series of forms. When the user clicks on save, I want full validation, but if the user clicks on "next", I want it to validate (and alert the user) for all fields except those who have no validation rules on them other than the "required" flag. This is so that I can save a partially completed form without having to alert the user to the missing fields until later (because they will want to save progress on their forms without having to complete them altogether).
Perhaps there's a way to get the fields with a jQuery selector/filter of some kind?
Not sure I completely understand the question and your use case, but it somewhat sounds like you may need to use custom form validation.
http://docs.angularjs.org/guide/forms#custom-validation
(you may need to scroll down a bit when first loading the link)
Basically you may need to add your own custom directive to control the validity of the inputs you have in mind.
Alternatively, and maybe not quite the "Angular" way, you can avoid using the data binding between the fields and model, effectively opting out of Angular validation. Obviously losing the data binding may be a bigger issue for you but you could get at those values with code outside of your Angular stack.

Ghost Submit Button Still in HTML Form Submission

I have a form that I'm validating with JavaScript before allowing the form to POST. The validations are done using the LiveValidation library, which I'm having defer doing the validations until the user attempts to submit the form. So, the Javascript is executing on the form's onsubmit event, returning false if the form is invalid to stop submission. The form also has multiple submit buttons to determine which action to take with the information on the server's side. The problem that I'm running into is that if the user clicks on one submit button, fails validation, and then successfully submits again, the first button clicked is also part of the POST, so the action taken on the server's side sometimes isn't the desired one. I thought that perhaps the problem was with the validation library, but now I'm starting to wonder if it isn't deeper. If a form's onsubmit returns false, does the set of POSTed variables get cleared or cached for the next submit?
Edit: OK, so this is an instance of the "I'm a dumbass" bug. I had added a hidden field with this name/value pair through JavaScript earlier, because of some funky business rules on the page. I just had to remove that, and it's all fine again.
Had to wait for some time to pass before it would let me answer my own question. Solution reproduced below:
OK, so this is an instance of the "I'm a dumbass" bug. I had added a hidden field with this name/value pair through JavaScript earlier, because of some funky business rules on the page. I just had to remove that, and it's all fine again.

Deselecting a form input and waiting for a function before submitting

I have a form with an input field where a user enters a unique identifier. I then have some jQuery code that upon the user moving away from the input field (blur) goes out and fetches details about the part and populates some fields on the page. The problem is if the user clicks the submit button before moving out of the input field the jQuery code never has a chance to load in the data and populate the necessary fields. Whats the best way to go about doing this? I thought about maybe setting the focus to body and then having an infinite loop that keeps checking the page until all fields that should be filled in have been filled in but I feel like some sort of event based solution would be better than unpredictable infinite loops. Any ideas?
Give the form an onsubmit event.
Have that event return false unless all the form fields are populated correctly.
In jQuery:
$("#formname").submit(function()
{ if (condition_not_met) return false; });
This will block the form from submitting until everything is in place.
The blocking will not work with JavaScript disabled, but seeing as you're using Ajax to fetch the correct fields, that probably won't matter.
I'm guessing you are making an ajax call in the blur function?
Could you disable the submit button (either on page load or on blur), and then enable it in the ajax callback?

Categories