What I want
When I submit a form, this specific field must to turn empty if the value is invalid.
I have this function that validate the value and set it empty if necessary.
The problem
When I try to submit the form with an invalid value the function clears the field and it seems to work, but if I click again to submit the form the old value (that doesn't apears in the field anymore) kinda bypasses the validation and is inserted into the database.
The val('') is cleaning the field but somehow the value remains.
The code
Here is the code I am using:
if (response==true) {
$("#license").val('');
}
What I already tried
document.getElementById('license').value = "" // didn't work at all
$("#license").val(' '); // with one space but I lose the placeholder visualization, and I need it
Could anyone help me? Thanks!
Related
Good night guys, I have a very simple angular question. I have a form, it has a specific field that I set the value for a patch value but at the same time I need to disable this field. However after the disable, the value is not sent to the back end to be inserted anymore. I've done the test and I saw that only with the patch value, the value is sent normally and inserted in backend normally, but when I disable it, it loses the value and is not sent to the back, I already tried onlyself but I didn't succeed , I would like your help if possible, thanks for your attention. Ah I know that html disable works, but I would like to know if there is any way for me to do this in typescript by disabling the field in the form.
iniciarSituacaoCadastro(){
if(this.visualizar){
this.formPesquisar.controls['address'].patchValue(Address.ATIVO);
this.formPesquisar.controls['address'].disable({onlySelf: true});
}
}
Use getRawValue() instead of value.
https://angular.io/api/forms/FormGroup#getRawValue
getRawValue() retrieves all values regardless of disabled status. The
value property is the best way to get the value of the group, because
it excludes disabled controls in the FormGroup.
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.
I am trying to disable a textbox in SharePoint WSS3 and force a specific value (given by another JavaScript function) but I can't seem to find the right way of doing it. I have come across different issues. Let's say I have a normal single line text value named prova and another one named Description. Description is required, prova is not.
First Issue: If the field IS required, even if there is something in the textbox, SharePoint says otherwise and does not allow me to insert the entry.
$(document).ready(function(){
//var value = someFunction(...);
var value = "test";
$("input[title='Description']").attr("disabled", "disabled");
$("input[title='Description']").val(value);
});
Second Issue: If the field IS NOT required SharePoint doesn't say anything but it inserts a blank value instead of the one given.
$(document).ready(function(){
//var value = someFunction(...);
var value = "test";
$("input[title='prova']").attr("disabled", "disabled");
$("input[title='prova']").val(value);
});
I have a feeling that tells me that there is some kind of SharePoint JavaScript function somewhere that listens for KeyUp or something. I have really no idea what to do now...
EDIT: It looks like the problem is related to disabling the textbox, if I comment the line where I disable the textbox it works in both scenarios. Maybe if I catch the insert request I can re-enable the textbox before SharePoint do the actual post. No idea how to do it though...
Your problem really is related to disabling the textbox first. By default disabled textboxes are not contained in the POST request in IE.
See this post: Disabled form inputs do not appear in the request or this one: how to save data by disabled text box?
What you actually want to do is set the readonly attribute of the field, not disable it (readonly="readonly"). The problem with that is that the readonly state sometimes looks the same as the default state, so you also have to add some CSS to make it look greyed out.
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.
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..