Cursor focus after page refresh - javascript

The idea is that I have two text fields and after I move from one field to another field the page refresh is done and there is no focus afterwards on the second field. I need to put cursor to the second field where it was previously before page update. Can somebody please tell me how to fix this issue? Thank you in advance.

if($('#textbox1').val()) {
$('#textbox2').focus();
}
You can do something like this, but need to take care of edit case (if any), so the condition can be anything as per your needs.

Check the empty field in document.ready and focus on it with .focus().
After filling your first field check both fields and focus on empty one.So on first page load it will focus on your first field and after second load it will focus on you second field.

Related

val('') clears the field but value remains

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!

Angular - How disable a field keeping the value

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.

How to disable Sharepoint textbox?

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.

Do something when input field gets updated through jquery

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.

reload a page without losing field values like in FireFox using javascript

I'm very new to JavaScript and HTML.
I have a simple html form that has some select fields. When the user selects the options from the fields, a function is called that takes the values of the fields, multiples the values against other field values and spits out the results to an input text field named "result".
This is all working great, however I would love a way that instead of outputting the results to a text field, it would output as standard text on the page.
What I did was call the calculate function the tag, within the body, I inserted a document.write(result), then I created a button that calls the calculate function in addition to location.reload().
In Firefox, it works perfectly where it KEEPS the options selected, calculates the results, reloads the page and updates the document.write(result) value on the page.
But in IE or Safari, it resets the select options values to the default settings.
I hope this makes sense and appreciate any help!
how about this:
every time the user selects an option, or makes any sort of a selection, serialize that control, and slap the serialized string to the end of the current window.location, then navigate to it.
also, you will need to add javascript to check the current url, figure out what selection was made, and pro grammatically change the control's values. this way, when the user refreshes the page, the url will contain all of his selections.
got it?
Instead of document.write you could setup an element used specifically to hold the output value much like you do currently with the input element.
In place of the current input element used to output the result..
<span id="calculationResult"></span>
Then to populate that value and avoid reloading the page at all so that your fields maintain current values..
document.getElementById("calculationResult").innerHTML = result;
if you need to append you can always just create text nodes and append to the element which would be preferred anyway.
In order to keep text boxes' content as is, set the button as type="button" and call the calculate function and document.write in onclick. No reload, no mess.

Categories

Resources