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.
Related
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 custom field on the header of a CRM form. I need to check if it has a value or not and then perform a certain function.
Now, for all fields on the form I can use
Xrm.Page.getAttribute("new_attributename").getValue();
However, for the field in the header that does not seem to work. How can I retrieve the value and check if it is null or has a specific value?
I tried this
document.getElementById("header_new_attributename_d");
That returned a value but I am stuck with absolutely no clue on how to get the value further?
I tried
document.getElementById("header_new_attributename_d").value
and that is undefined.
How can I get the value of the field and check if it is null?
The supported way is to add the field also to the body of the form and set it to be not visible by default.
In this way you can use the supported method getValue and the field is only displayed inside the header.
So I tried to do something like this -
$('#price').val(price);
price is 300, and it shows good on browser, in input field, but when I want to take it out and mail it with PHP, in $_POST['price'] it doesn't show up, How can I insert something in inputs value with JavaScript, so I can mail it? It seems this is not an insertion in value, but just a feature to display something, correct?
Maybe this code can help you
document.getElementById('yorInputID').value = "Your Value";
There are a few possible reasons:
1) Your input field is not inside the form.
2) You are actually using a GET and not a POST.
Assuming that you can see the value updated in Firebug or Chrome's equivalent, it's gotta be one of those. Switch over to using $_REQUEST and see if that changes anything.
Your input for #price needs to also have a name "price"
<input id="price" value="price" />
From your question I'm assuming that this input is hidden -- and if that's the case I want to advise you not to rely on hidden fields + Javascript to provide you with security. It's so easily hackable I wouldn't even call it hacking.
Make sure the input is not "disabled" when the form submits.
if it's disabled the form don't send it.
I'm wondering if there is a simple way to reset the values of a form that had already been used, using javascript. I had tried to make a function that would set the values to an "empty string" (not sure if that's what it's called in this case, but '') and then to their default values, but this didn't work. And I had tried form reset, but that seemed to delete my form. I would be okay with restoring default values except I couldn't figure out how to set the radio button to NULL or nothing.
Thanks for any suggestions.
You can use <input type="reset" />[MDN], which will render a button that resets the form back to the state it was in when it was loaded.
Here's an example: http://jsfiddle.net/zEYEa/embedded/result/
I have input field
<input type="text" name="vehicle_make[]" id="make1"/>
and i have help dropdown that updates this field if user choose to do so. I do it trough standard jquery code
$("#make1").val("value");
Problem is, since i use validate plugin to validate this field, if user click on validate before entering anything in that box, he will get notice that he needs to fill it, but then if he fills it trough dropdown, validate plugin will not detect it until user click on submit again.
I know i could call submit in function in which i process dropdown, but i think that it is not right solution, since i would need to check if validation is already done before doing that (since if it is not, it would start validation before i want it to start).
I also need to tie some other things to that field also, so i would like to know is there is a way in which i could write function so it always check if field is filled, even if user did not fill it directly.
Sorry if i didn't explain everything right, this is my first message here.
Try this
$("#make1").change(function(){
//do something there
});
I have found solution. First, i created js variable form_submitted, and added onclick event to submit button, to change value of variable form_submitted to yes. Then, i created function:
function update_validation(){
if(form_submitted == 'yes'){
$("#my_form").valid();
};
};
that i call when user do something that is not detected regularly with validate plugin. This function manually starts validation again, but only if it has been started before by clicking on submit.