Page 1 of 2
How do I re-enable a disabled field in JS?
Posted: Wed Aug 16, 2017 5:06 am
by simonmlewis
I have a Cart page that for some reason, is disabling the Postcode field. It's down to the theme.
So I am wondering if I use a getelementbyname, if I can disable the disabled function (if that is the cause).
To try and test it out, I am doing this, but to no avail.... trying to disable the field.
Code: Select all
<script>document.getElementByName("wc_address_validation_postcode_lookup_postcode").disabled = true;</script>
<form method='post'>
<input type='text' name='wc_address_validation_postcode_lookup_postcode' class='input-text'>
</form>
Any ideas?
ps we have to use Name instead of ID as the coded plugin uses Name. Not ID.
Re: How do I re-enable a disabled field in JS?
Posted: Wed Aug 16, 2017 5:25 am
by requinix
There is no "getElementByName" function. There is a "getElementsByName", which returns a list, though.
If the problem is the theme disabling the postcode then the solution is to make the theme not disable the postcode. Adding more Javascript just makes things more complicated.
Re: How do I re-enable a disabled field in JS?
Posted: Wed Aug 16, 2017 5:35 am
by simonmlewis
Mmmm yes I quite agree, but where in their code, in the deep Wordpress theme, it is disabling that sort of thing, I don't know.
Trouble is, it's a third party plugin direct from Woocommerce. So something is causing it to not work. I wondered if it was an Ajax thing, but not sure.
Should this work in my test?
Code: Select all
<script>
document.getElementsByName("wc_address_validation_postcode_lookup_postcode")[0].disabled = false;
</script>
<form method='post'>
<input type='text' name='wc_address_validation_postcode_lookup_postcode' class='input-text'>
</form>
Happy to provide the plugin used, and the theme used. But would require you to have a copy of the theme to test it.
Re: How do I re-enable a disabled field in JS?
Posted: Wed Aug 16, 2017 6:45 am
by requinix
It looks like it will work, yes. Make sure you're executing that after the page has loaded, or at least that you're putting the <script> after the <form>.
To find why it's disabled, first look at when it's disabled. Does the source of the page show the field as disabled? If so then PHP code is responsible. If not then you know it is happening Javascript.
Either way you can search the plugin and/or theme code for "postcode" and see what shows up.
Re: How do I re-enable a disabled field in JS?
Posted: Wed Aug 16, 2017 9:27 am
by simonmlewis
This is the HTML it's rendering:
Code: Select all
<p class="form-row form-row-first wc-address-validation-field wc-address-validation-billing-field">
<input type="text" class="input-text" name="wc_address_validation_postcode_lookup_postcode" placeholder="Enter Postcode" value="" />
</p>
<p class="form-row form-row-last wc-address-validation-field wc-address-validation-billing-field">
<input type="hidden" class="wc-address-validation-address-type" value="billing" />
<a href="#" class="button">Find Address</a>
</p>
<div class="clear"></div>
<p class="form-row message notes wc-address-validation-results wc-address-validation-field wc-address-validation-billing-field">
<select name="wc_address_validation_postcode_lookup_postcode_results" style="width: 100%" class="wc-address-validation-enhanced-select select billing"></select>
</p>
<hr/>
<p class="form-row form-row-first wc-address-validation-field wc-address-validation-shipping-field">
<input type="text" class="input-text" name="wc_address_validation_postcode_lookup_postcode" placeholder="Enter Postcode" value="" />
</p>
<p class="form-row form-row-last wc-address-validation-field wc-address-validation-shipping-field">
<input type="hidden" class="wc-address-validation-address-type" value="shipping" />
<a href="#" class="button">Find Address</a>
</p>
<div class="clear"></div>
<p class="form-row message notes wc-address-validation-results wc-address-validation-field wc-address-validation-shipping-field">
<select name="wc_address_validation_postcode_lookup_postcode_results" style="width: 100%" class="wc-address-validation-enhanced-select select shipping"></select>
</p>
And this does in fact appear at the bottom of the page:
Code: Select all
<script type='text/javascript'>
document.getElementsByName("wc_address_validation_postcode_lookup_postcode")[0].disabled = false;</script>
But it isn't enabling the form field for Postcode.
Re: How do I re-enable a disabled field in JS?
Posted: Wed Aug 16, 2017 9:33 am
by requinix
Are you sure the field is actually disabled? Does the DOM say it's disabled, like
Code: Select all
alert(document.getElementsByName("wc_address_validation_postcode_lookup_postcode")[0].disabled); // true?
or is there some other mechanism in effect?
Again, find out what the theme/plugin is doing.
Re: How do I re-enable a disabled field in JS?
Posted: Wed Aug 16, 2017 9:44 am
by simonmlewis
That generates a popup that says "false". What does that mean?
Re: How do I re-enable a disabled field in JS?
Posted: Wed Aug 16, 2017 10:29 am
by requinix
Means it's not actually disabled.
Re: How do I re-enable a disabled field in JS?
Posted: Wed Aug 16, 2017 10:34 am
by simonmlewis
Mmmmm damn it. So is there any way of finding out what is causing it to (I use this term cautiously) ... be disabled? Or readonly.
I suppose there is the chance that the Theme just has some sort of conflict with it.
Do you know of any other Wordpress Plugins that do Post/Zipcode lookups? Enter code, choose address from dropdown etc.
Surely there isn't just the one out there. Tho it is by WooCommerce. lol.
Re: How do I re-enable a disabled field in JS?
Posted: Wed Aug 16, 2017 3:48 pm
by requinix
simonmlewis wrote:So is there any way of finding out what is causing it to (I use this term cautiously) ... be disabled? Or readonly.
I'll say it one more time before I give up:
Look at the theme or plugin, whichever you're talking about as being the source of the problem, to see how and why it is "disabling" the field. Then you can react accordingly.
Re: How do I re-enable a disabled field in JS?
Posted: Wed Aug 16, 2017 4:22 pm
by simonmlewis
I'll give up too. Absolutely no way of finding out. Without asking theme developers. Who are vague.
Re: How do I re-enable a disabled field in JS?
Posted: Thu Aug 17, 2017 1:20 am
by requinix
Is the source code obfuscated?
Re: How do I re-enable a disabled field in JS?
Posted: Thu Aug 17, 2017 2:41 am
by simonmlewis
No, the code is all there, but the cause to the problem could among any one of all the files in the folder structure.
Finding out which one it is, is likely to be impossible.
We should be getting some theme issues sorted next week, and the theme people may be able to help.
Re: How do I re-enable a disabled field in JS?
Posted: Thu Aug 17, 2017 9:54 am
by requinix
simonmlewis wrote:Finding out which one it is, is likely to be impossible.
Not even remotely the case, but it's clear you don't even want to try so whatever.
Re: How do I re-enable a disabled field in JS?
Posted: Thu Aug 17, 2017 10:00 am
by simonmlewis
How on earth do I "try", when it i Wordpress, and is full of JS and CSS and all sorts of included PHP files from all over.
I just would not know where to start.