- Posts: 84
- Thank you received: 1
Make custom field default text disappear onfocus
The idea is that I want to add a description of the field for the user. The text title/label is not enough as a description field.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
You have to edit the file "administrator/components/com_hikashop/classes/fields.php" function "display()" in the class "hikashopTextarea", and in the .js add the desired code to remove the content on focus.
Please Log in or Create an account to join the conversation.
can you give me the string to achieve the following:
onfocus delete default value
and
onsubmit if value is the default value don't submit value
Please Log in or Create an account to join the conversation.
Why not using the HTML5 "placeholder" tag ?
Compatible with new browser and it does not touch to the input value (so no problem with the submission of the form).
Otherwise, the javascript will be very complex.
Regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Please Log in or Create an account to join the conversation.
Also, if it's not compatible with older browsers it might be a problem because it is the only description of the field. So if it is not compatible then there will be no description of the field.
Please Log in or Create an account to join the conversation.
You can simply use the content of $js but put this line out the if condition like:
And is the textarea is empty, it will reset the default value. You can add css properties in the javascript to change the color for example to show that the text is the description.
ps: for the previous method, you have to set a default value in the custom field configuration.
Please Log in or Create an account to join the conversation.
Problem 1: When I add to cart it submits the default value. I don't want default value submitted.
Problem 2: Why is it when I have a custom field enabled and I click "add to cart", it takes me to the checkout page? As opposed to, when I don't have a custom field, it simply adds to the cart and stays on the same page? I'd like to have the custom field enabled and stay on the same page once "add to cart" is clicked.
Please Log in or Create an account to join the conversation.
Problem 1: As you said before, you have to add a onsubmit in the form, check the custom field value and if it's equal to the default value, erase it.
Problem 2: The custom fields should not change the way the form is submitted, and the redirection. Have you edited any view related on the custom fields - product - cart ?
Please Log in or Create an account to join the conversation.
I tried this but didn't work:
Problem 2: No. All I know is that when the custom fields are enabled, once the add to cart button is clicked from the product page it goes to the checkout. If the custom field is not enabled it stays on same page.
Please Log in or Create an account to join the conversation.
I am really sorry to insist but, this is not the right solution.
As I said, using such trick will be very complicated for the javascript. Using the "placeholder" attribute will be easier and could be easily compatible with old browser.
By default, the placeholder attribute is compatible with:
* Firefox 4.0+
* Opera 11.01+
* Chrome 3.0+
* Safari 3.0+
* Internet Explorer 10+
For old version, there are some script, like a little jQuery script:
About the attribute, you can set the placeholder attribute like other attributes (like the class or the javascript events).
So, something like:
Best regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Please Log in or Create an account to join the conversation.
Can you give me a step by step and where I should put the codes you mentioned?
Please Log in or Create an account to join the conversation.
$js = 'onfocus="if(this.value == \''.$value.'\') this.value = \'\';" onblur="if(this.value=
'\') this.value=\''.$value.'\';"';by:
$js = 'placeholder="'.$value.'"';
in the field.php file.
Please Log in or Create an account to join the conversation.