I'm trying to write some javascript code that prefills an address field on homedepot. My code works and is adding the address values to the fields, however, homedepot is doesn't accept the address until I actually detects that each field has been entered. Setting the .val() for each field does not seem to be enough. If I go in after setting the .val() for each and manually type at least 1 character it will work and accept the address. How can I trigger whatever change event needs to happen so that I don't have to do this manually?
I tried using the change trigger as shown here, but it doesn't work.
$('#lastName').val('Doe').trigger('change');
All of the actual html form code is on homedepot.com checkout page. I'm just typing the above command for each of the address fields (lastName, firstName, zip, etc) into the developer console in chrome.
You need just call change method
$('#lastName').val('Doe').change();
Give it a try...
Related
I'm building a Chrome extension that enables the user to insert canned responses into Youtube comments on their channel. I insert the text using textarea's value property:
getHighlightedComment().querySelector("textarea").value = cannedResponseText
The problem is, the textarea doesn't adapt its size and the submit button doesn't get enabled until I type in another letter manually.
I have a different extension installed that has a similar functionality that doesn't have these problems, so it must be possible.
I already tried sending keypress/keydown/keyup events manually, but they seem to not work inside textareas. Nothing happens in response to them.
I guess you need to trigger some event on your field after actual change Here is how you can deal with it.
UPD.
I tried sending keypress/keydown/keyup events but it seems they don't work inside textareas. Nothing happens.
I guess it is more about onchange event.
Also you need to check the CSS of your textarea - rows are not hardcoded, height and max-height is not hardcoded (has value 'auto').
Here are some workarounds to update it with JS - https://stackoverflow.com/a/25621277/9994697
I would like to change the order in which the fields in a form get checked.
The field Email should be checked before the field City. They are both obligatory.
I would also like that when the email address is invalid only one Popup is shown (by default I get two- one saying the email is invalid and one saying that the field cannot be null)
Is it possible to change the order of the checks and do the custom checks before the system ones?
Marco
The only supported method of changing the order in which the fields get checked, is changing the order on the form. I'm assuming that CRM just loops through it's collection of controls to perform the field validations. You could attempt to dive into the CRM javascript and figure out a method to hijack it.
A supported way of handling it would be to make the fields not required (either via javascript on the OnLoad, or updating the entity definition itself), and then on the OnSave, writing your own field validation. It's a lot of extra work, and you lose the little red asterisk showing the field is required, but you'd be able to evaluate them in the order you'd like (or display a single message with everything that's missing (why that isn't done by default in CRM I'll never know)), and be able to fix your email invalid / not null message.
CRM does not loop through its collection of controls as specified in the answer above.
The validation of the fields(business required) on a CRM form happen in the order in which they were added to the form, irrespective of where they are placed in the form. So, as of now, the only way to change the order in which they are validated is to add them in the same order as you want them validated.
So far.. I believe the only option to work around this is stated in this link.
http://social.microsoft.com/Forums/en-US/8f402463-23aa-4bc1-862b-4f4093a0cce8/required-fields-order-of-validation?forum=crmdevelopment
Basically you would need to use javascript. Have only one field as mandatory. On change of this field set the next field (in the correct order) to mandatory and so on.. hectic but only way.
I ran across a site where during registration, the input field for the nickname won't let me type in more characters and/or change focus to a different input field, while it is using a jQuery AJAX call to check if the nickname is available.
Just for fun I decided I want to get to the bottom of it.
I thought this would be an easy task but I was wrong.
I can't seem to find what causes it using Firebug.
How can I see all events that are bound or get fired off when I type something?
If I have a required field on my form within my MVC3 page, and try submitting the form, the validation fires and the input control is given a light-red background color (fill) and it also shows a validation message. If I type in the input control, it will detect the value and remove both the coloring and validation method. This is how it should work.
In my case, I have mailing address fields, most of them required. I have an option on my site to select an address in a drop down list. When an address is selected by the user, all the address fields filled in using client side javascript. However, when I do this, my validation message and color aren't going away. So I need to somehow force the validation check.
How is this done?
Thanks in advance.
The reason validation fires for your inputs is because they hook up to your change, focus, blue, keypress, etc events. For a scenario of where you fill the fields in with script you'll need to specifically call each element that had it's value populated. The reason for this is because the change event will not be fired. Just select the element with jQuery and call the valid method on it for jQuery Validate. The valid function will force validation on the element when called.
jQuery Validate Valid Documentation
Example
$("#mySelect").change(function() {
$("#myElement1").val("Some Value");
$("#myElement1").valid();
});
I'm trying to detect when a browser places a saved username and password into the input fields. I've looked at this post , but I don't have the option to change this functionality, and the other solutions on don't work.
Basically, I have a disabled login button if the fields are empty on load. But when a browser fills in the input, it doesn't enable the button. I'm trying to find how to see if it changes.
I'm using jQuery and JS.
I've tried .change, on .ready, on .load, and all. It seems to happen after the .load event.
Does anyone know a solution to this? I would like to avoid using any sort of timeout.
I think there is no way to detect if the browser has some buil-in feature that pre-populates the fields.
You could solve the problem with the a timer that enable the button, if something is there.
Something like this:
setInterval(function (){
if($("#username").val()!=""){
$("#loginbutton").attr("enabled","enabled");
}
},1000)
The key thing is that the field will be populated without there having being any keypresses in the field.
So if you trap .keypress on the input field to know if a key is any pressed, then if you get to submitting the form and find there were no keypresses despite a value being there - then you can be somewhat sure that the browser pre-populated it.
If you want to know before submitting (soon after the page loads), you'd want to run a check on an interval that sees if the value has changed despite no key presses.
As #japrescott pointed out, you might want to check for .focus as well in case the user pastes a value in.
Haven't test this, but couldn't you simply compare the default values of each field to the values of each field after the page is loaded (or .2 seconds after the page is loaded if that's an issue)?
Give a shoot to Jquery .live() function
$('.element').live('load', function(){
enableLogin();
});