Hello
I have made two input fields.
What is want is to show “Fill Out this Field” like below in case it left empty.
{% if product.title contains ‘oh Wanted Studio 3D Customized Car Plate Keychain’ %}
Hello
I have made two input fields.
What is want is to show “Fill Out this Field” like below in case it left empty.
{% if product.title contains ‘oh Wanted Studio 3D Customized Car Plate Keychain’ %}
Hi @amazezones ,
As your requirement and the code that you supply:
To add a “Please Fill Out This Field” tooltip in case the input fields are left empty, you can use the HTML title attribute for the input elements. This attribute allows you to specify text that will be displayed as a tooltip when the user hovers over the input field.
Here’s an updated version of your code with the added tooltip:
{% if product.title contains 'oh Wanted Studio 3D Customized Car Plate Keychain' %}
<!-- Edit Add customization box for keychain-->
<div class="wrapline">
<p class="line-item-property__field "
<!--<label for="monogram1" class="label-required">Enter Plate Number (Max 5 Digits)</label>-->
<div class="row{% if section.settings.layout == '1' %} justify-content-center justify-content-md-start{% endif %}">
<input class="ep_inline_block plate_number_az" type="text" placeholder="Enter Plate Number (Max 5 Digits)" id="monogram1" style="width:285px; max-width:100%;" name="properties[Plate Number]" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');" pattern="\d{1}" maxlength="5" required title="Please Fill Out This Field">
</div>
<!--<label for="monogram">Enter Code</label>-->
<div class="row{% if section.settings.layout == '1' %} justify-content-center justify-content-md-start{% endif %} mb-20">
<input class="ep_inline_block code_number_az" type="text" placeholder="Enter Code" id="monogram" style="width:130px; max-width:100%;" name="properties[Code]" oninput="this.value = this.value.replace(/[^0-9,A-Z,a-z.]/g, '').replace(/(\..*?)\..*/g, '$1');" pattern="\d{1}" maxlength="2" required title="Please Fill Out This Field">
</div>
</div>
In this code, I added the title attribute to both input elements, providing the text “Please Fill Out This Field.” This text will be displayed as a tooltip when the user leaves the field empty and tries to submit the form.
Hope it helps!
Have a nice day! ^^
its not working… without filling still I can add product to the bag…
As your update requirement, your input fields must be in a form, and have a submit event.
Because the code you provided is only a small part of the entire liquid file of the theme store, I can only give you an example to visualize the solution, but cannot make the correction absolutely accurate.
Below is an orientation on how to do it, you can do the same.
Good luck.
{% if product.title contains 'oh Wanted Studio 3D Customized Car Plate Keychain' %}
<div class="wrapline">
<form onsubmit="return validateForm()">
<div class="row{% if section.settings.layout == '1' %} justify-content-center justify-content-md-start{% endif %}">
<input class="ep_inline_block plate_number_az" type="text" placeholder="Enter Plate Number (Max 5 Digits)" id="monogram1" style="width:285px; max-width:100%;" name="properties[Plate Number]" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');" pattern="\d{1}" maxlength="5" required data-tooltip="" title="">
</div>
<div class="row{% if section.settings.layout == '1' %} justify-content-center justify-content-md-start{% endif %} mb-20">
<input class="ep_inline_block code_number_az" type="text" placeholder="Enter Code" id="monogram" style="width:130px; max-width:100%;" name="properties[Code]" oninput="this.value = this.value.replace(/[^0-9,A-Z,a-z.]/g, '').replace(/(\..*?)\..*/g, '$1');" pattern="\d{1}" maxlength="2" required data-tooltip="" title="">
</div>
<button type="submit">Add to Bag</button>
</form>
</div>
<script>
function validateForm() {
var plateNumber = document.getElementById("monogram1").value;
var code = document.getElementById("monogram").value;
if (plateNumber === "") {
setTooltipMessage("monogram1", "Fill out this field");
return false;
}
if (code === "") {
setTooltipMessage("monogram", "Fill out this field");
return false;
}
// Add additional validation logic if needed
return true;
}
function setTooltipMessage(elementId, message) {
var inputElement = document.getElementById(elementId);
inputElement.setAttribute("title", message);
inputElement.dataset.tooltip = true;
}
</script>
{% endif %}
In this example, I added a form element around your input fields and a submit button. The onsubmit attribute of the form calls the “validateForm” function, which checks if the required fields are filled. If any of the fields are empty, it call " setTooltipMessage " function that sets the “title” attribute and a custom “data-tooltip” attribute on the input elements. and returns false, preventing the form from being submitted. Otherwise, it returns true, allowing the form to be submitted.
hey BSS Commerce, thx of the reply… the code is not working properly… first if I enter more than 1 digit I get notification that format is not matching. 2- add to cat button is different than the page design 3- after clicking add to cat noting is added to cart
this is full code
{%- if template_layout == ‘5’ -%}
{%- assign centered = true -%}
{%- endif -%}
{%- unless is_quick_view -%}
{%- assign change_history = true -%}
{%- endunless -%}
{% capture variants_select_html %}
{%- elsif settings.reviews_type == ‘loox’ and product.metafields.loox.num_reviews -%}
{%- endif -%}
{{ 'products.product.sku' | t }}: {{ sku }}
{{ 'products.product.barcode' | t }}: {{ barcode }}
{{ 'products.product.availability' | t }}: {% if available %}{% if quantity > 0 %}{{ 'products.product.availability_value_in_stock' | t: count: quantity, item: item }}{% else %}{{ 'products.product.availability_value_in_stock_without_counter' | t }}{% endif %}{% else %}{{ 'products.product.availability_value_out_stock' | t }}{% endif %}
{{ 'products.product.type' | t }}: {{ type }}
{{ 'products.product.vendor' | t }}: {{ vendor }}
{%- if compare_at_price > price -%} {%- assign price_save = compare_at_price | minus: price -%} {%- assign price_save_money = price_save | money -%} {%- assign price_save_procent = price | times: 100 | divided_by: compare_at_price | minus: 100 | times: -1 -%} {{ 'products.product.price_sale_details_html' | t: price: price_save_money, procent: price_save_procent }} {%- endif -%}
{%- endif -%} {%- if settings.product_info_show_taxes -%} {%- if shop.taxes_included or shop.shipping_policy.body != blank -%}{%- if settings.app_klarna_enable -%}
{%- assign klarna_app_blocks = section.blocks | where: ‘type’, ‘klarna_app’ -%}
{%- for block in klarna_app_blocks -%}
{%- when ‘icon_with_text’ -%}
{{ 'products.product.stock_countdown_html' | t: quantity: quantity_html }}
{%- if settings.product_info_show_stock_countdown_range -%}{%- when ‘visitors’ -%}
{%- when ‘border’ -%}
{%- when 'options' -%} {%- if settings.product_show_custom_options -%} {%- unless product.has_only_default_variant -%}{% if product.title contains ‘oh Wanted Studio 3D Customized Car Plate Keychain’ %}
{% capture cart_icon_name %}{{ settings.cart_icon | default: ‘icon-theme-109’ }}{% endcapture %}
{%- if settings.product_info_button_layout != ‘3’ and settings.product_info_show_quantity-%}
{%- assign product_form_id = ‘product-form-’ | append: section.id -%}