How To Make A Field Mandatory In Product Detail Page Tabs

There are different tabs on the product detail page and what I want is to make few fields mandatory on different tabs so that if the vendor creates a new product he should get an error message if all the mandatory fields ( on different tabs) are not filled?



I tried using the class cm-required on the fields in tpl field but that is just a display of asterisk not a field check. Please advise?

hi,



It should work via CSS class “cm-required” so possibly it was added to wrong HTML tags. Please check how it should look like:

```php


Field



```

Comments:
1. CSS class "cm-required" is added to LABEL
2. FOR attribtute for LABEL = ID attribute for INPUT

Please check it and let us know result.

best regards,
WSA team

Damir,



Thanks for the response, I did the same thing but now I have figured out why its not happening. I applied this on the weight field in shipping and by default its adding 0.00 in the content , how can we validate that the content is not 0.00 and then raise an alert that please fill this value while creating a product.



Thanks.

You may remove the zero value 0.00 and make field required. For this please open the file “design/backend/templates/views/products/components/products_shipping_settings.tpl” and replace the line:








with:








and line








with









p.s. Also please don't forget to clear template cache.



Let us know if it helps.



best regards,

WSA team

Hi Damir,



Thanks for this it works but now the issue is since the Shipping Tab is having this Weight field , if the user is not on the Shipping Tab he never comes to know that the validation error is coming. Can we somehow show a popup ( javascript) error to let the user know about this or may be some other notification ?



Thanks.

The system should open the corresponding tab to the user. It is default CS-Cart behavior. Please check

hi,



eComLabs is right, it should work by default.

If no, please provide us with the temporary FTP access, our specialists can check the issue.



best regards,

WSA team

Awesome, it works post cleaning the cache. :shock: Strange behavior

Could you please explain where the CS class should be added in order to make a feature "rewuired"? I have a feature (size) which I would like to make a required field. How can I do this?

Many thanks in advance

You can add cm-required class to label elements here

design/backend/templates/views/products/components/product_assign_feature.tpl

This file has hooks as well

Thank you ecom. Can you please indicate what I should replace with what, so as not to mess anything up. I remind you that I need to make a specific feature required (i.e. size).

Thanks again, much obliged

Try to replace

<label class="control-label" for="feature_{$feature_id}">

with

<label class="control-label{if $feature_id == 123} cm-required{/if}" for="feature_{$feature_id}">

where 123 - feature ID, can be found in the admin panel

(!) Not tested

Thanks eCom but it didn't work. I get a "service unavailable" screen when trying to sreate a new product or see a product which is already in store.

Right click/inspect that screen and post the comments which is the stack trace and report of the error. Most likely you have a typo in your Smarty syntax.

Thanks eCom but it didn't work. I get a "service unavailable" screen when trying to sreate a new product or see a product which is already in store.

Our code is correct. Please make sure that everything is copied correctly

Tanks eCom. It works up to the point that it makes the feature "required". However, even when I do select a feature, it still marks it in red (message saying the feature is required) and does not let me save. Any ideas?

It is hard to say anything without examination, sorry

I tested the code from eCom Labs and it really works, however it makes also impossible to save the product since even when you fill the feature with information it still send a warning message saying that the field is required like if it was empty. I am trying to debug to find a solution.

I tested the code from eCom Labs and it really works, however it makes also impossible to save the product since even when you fill the feature with information it still send a warning message saying that the field is required like if it was empty. I am trying to debug to find a solution.

This was exactly how it was for me as well. Let me know if you manage to find a solution.

Make sure that

for="feature_{$feature_id}

Matches the id of your form field. I.e. if you have an input element named


Then the for parameter in the label tag must resolve to "feature_123".