Profile Field Required For Some Countries

Hello,

what is the way to add extra profile field required only for certain countries on checkout registration page?

thanks

I do not know easy way to do it. Additional custom development work is required

ok thanks.

should it work if to make extra field visible / not required and add extra condition in profile_fields.tpl and to make it required if country match?

ok thanks.

should it work if to make extra field visible / not required and add extra condition in profile_fields.tpl and to make it required if country match?

<input {if $field.autocomplete_type}x-autocompletetype="{$field.autocomplete_type}"{/if} type="text" id="{$id_prefix}elm_{$field.field_id}" name="{$data_name}[{$data_id}]" size="32" value="{$value}" class="ty-input-text <strong>{if $country == "XX"} cm-required" {/if} />

It should be checked dynamically after the country is changed, isn't it? In this case you should run special script after the profile details are updated to enable/ disable new field

I added test script for dynamic country check up in profile_scripts,tpl for extra notification as follows:

        $(_.doc).on('change', '.cm-country', function() {
 	    var country_val= $(this).val();
   	    if (country_val==="DE") {
        $.ceNotification('show', {
            type: 'W', 
            title: _.tr('warning'), 
            message: _.tr('cannot_buy'),
		});
	};

});

.I think just enable/disable field is not enough, may be adding cm-required to the label for the specific field will do it?

What would be the right way to add field id check up and add class to its label? I need something like this

if (field_id == 37) {

$('label').addClass('cm-required');

}

thanks

I vote for specific class due to easy management

Note that the 'cm-required' class is usually applied to the label versus the input tag.

Making it required only means "something entered" unless you use a reg_ex to validate it. Otherwise you'll have to validate it in a controller (addon preferred) when the data is POSTed.

Note that the 'cm-required' class is usually applied to the label versus the input tag.

Making it required only means "something entered" unless you use a reg_ex to validate it. Otherwise you'll have to validate it in a controller (addon preferred) when the data is POSTed.

You can also use regular expressions in the template with the cm-regexp class

https://docs.cs-cart.com/4.7.x/developer_guide/core/front-end/microformats.html