Tips and Tricks HQ Support Portal › Forums › WP eStore Forum › WP eStore Tweaks › Select Mandatory Customer Input Fields for Certain eStore Products
- This topic has 5 replies, 2 voices, and was last updated 8 years, 8 months ago by admin.
-
AuthorPosts
-
March 11, 2016 at 10:42 pm #13342amazing2061Member
The following link provides instructions on how to make a customer input field mandatory:
Can I require or make mandatory the Collect Customer Input field?
My question is would not these instructions have a site wide affect on all customer input fields? Is there a way to only target select customer input fields that I need to make mandatory? Thanks.
March 11, 2016 at 11:50 pm #72728adminKeymasterWe can add a CSS class in the button form that has the product ID in there. This will allow you to target “collect input” field of certain products only.
Let me know if that will help.
March 12, 2016 at 12:33 am #72729amazing2061MemberThat would help! Can you please share? Thank you
March 12, 2016 at 2:55 am #72730adminKeymasterokay, I have added the product specific classes in there. Sent you an update via email.
Now you can apply a tweak like the following to trigger this code for a particular product ID. In this example code the product ID is 2.
jQuery(document).ready(function($) {
$('.eStore-button-form-2).on('submit', function() {
var $thisbuttonform = $(this);
var custom_input = $thisbuttonform.find('.eStore_collect_input').val();
if(!custom_input.trim()){
alert('Please enter a value in the custom input field');
return false;
}
});
});March 12, 2016 at 1:28 pm #72731amazing2061MemberThank you again for the update. Incredible support…same day, unbelievable!
Before I install the update, am I to assume the code you posted here is added as follows:
“Open the “lib/eStore_read_form.js” file and add the block of code at the beginning of that file”
Also, I will have several instances of a custom input field I will want to make mandatory, how would I modify the code you provided if I have say for example four products with product ID’s of 3, 4, 5, 6? Sorry, not very good with code and how it works, but I’m learning. Thanks again!
March 13, 2016 at 8:15 pm #72732adminKeymasterYou can do the following to apply this to a few of your products (in this example it will do it for product ID 2,3,4,5 and 6:
jQuery(document).ready(function($) {
$('.eStore-button-form-2, .eStore-button-form-3, .eStore-button-form-4, .eStore-button-form-5, .eStore-button-form-6').on('submit', function() {
var $thisbuttonform = $(this);
var custom_input = $thisbuttonform.find('.eStore_collect_input').val();
if(!custom_input.trim()){
alert('Please enter a value in the custom input field');
return false;
}
});
}); -
AuthorPosts
- You must be logged in to reply to this topic.