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
Related
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();
I have a custom form control (a directive which is not an input element) which implements ng-model (as suggested here) and it works fine. Validation is triggered on the form submit and the directive is made valid/invalid correctly.
The problem is how to display an error message. I tried like for normal form input fields:
ng-show="form.fieldName.$error.required"
but I cannot access field through name. form.fieldName is undefined.
Please make sure that you defined your form name inside of form tag. After that try to print formname.fieldname
Actually the problem was with transclusion. Once I fixed it element was normally accessible through the name.
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
I have a JSP registration form in my site. Also I have a text box with placeholder="opt" and id="ext" in my JSP registration page which is an optional field. On clicking submit button the value of placeholder is submitting to the database on leaving the optional field blank. But I want to clear the value of text box on leaving it blank. I've tried the below methods. But those methods are not working in my case.
document.getElementById("ext").value="";
document.getElementById("ext").placeholder="";
document.getElementById("ext").setAttribute("placeholder","");
I've also tried the same methods with jQuery. That also is not working.
Can anybody suggest a solution.
You can prevent the value of placeholder entering into DB b having a condition on servlet (business logic) i.e the page handling the DB operations.
Check on servlet like as below:
if(request.getParameter("<Parameter name Here>").equals("<Plaeholder value>"))
{
// set value of <Parameter name Here> nullhere
// Do insert option here
}
The solution will be valid untill you wil change the placeholder's value.
Small but boring issue:
We have an Form field inside an DojoX Grid (1.2). If the user changes the value inside this field, and is hitting the "Submit" Button without clicking somewhere else the new value is ignored.
Is there any way to "accept" all Values entered inside the field, when hitting submit? Or something like "onMouseOut" Accept value?
An colleague has found an solution:
grid.edit.apply();
before submit..