THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline


Hi,

I want to disable the State field from the registration Form.

How do I go about it without breaking anything?

Regards,

Offline


Guys, please say something

Offline


The state field isn't required so you can delete the form field in the register.html

Offline


Bonjour,

I'm going back on this thread because I have a slightly similar pbm.

First of all, the answer of RONANAUPETIT seems bizarre ... on my installation, the state field IS labelled as "required", but I do not understand why that would prevent me from suppressing the field from register.html ? because that would break some processing ? I'm supposing this is an english language problem, RONANAUPETIT meant that if I do not need the field I can erase it ?

My question now: yes the pbm with this field is that it is "required" so for french users it's a problem ... Is there a way to have a relation between the country and the state ? (if France is choosen, state not required ...). More simple, how do I make this field as not required without suppressing it ?

Pierre.

Offline


Pierre, from Thelia 2.3, states are fully supported, and you can manage them from the back-office.

On the front side, the states are managed in the various address forms with Javascript, to keep the state field synced with the country field.

Whatever, the state field is not required by the Thelia back end, and you can safely remove it from the forms in the front office template.


OpenStudio Toulouse

Offline


Hi,
Sorry, I don't know why I do not get the emails advising me of answers (well sometimes I do, sometimes not).

Anyway, question: how do I remove it from the forms ? in the register.html I have (for the state)

                        {form_field field="state"}
                            <div class="form-group group-state{if $error} has-error{/if}">
                                <label class="control-label col-sm-3" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
                                <div class="control-input col-sm-5">
                                    <select name="{$name}" id="{$label_attr.for}"
                                            data-thelia-state="1" data-thelia-country="#{$countryFieldId}" data-thelia-toggle=".group-state"
                                            class="form-control"{if !isset($error_focus) && $error} autofocus{/if}>
                                        <option value="">-- {intl l="Select State"} --</option>
                                        {loop type="state" name="state.list"}
                                            <option value="{$ID}" data-country="{$COUNTRY}"
                                                {if $value != ""}
                                                    {if $value == $ID}selected{/if}
                                                {/if}
                                                >{$TITLE}</option>
                                        {/loop}
                                    </select>
                                    {if $error }
                                        <span class="help-block">{$message}</span>
                                        {assign var="error_focus" value="true"}
                                    {/if}
                                </div>
                            </div><!--/.form-group-->
                        {/form_field}

I don't see where is the "required" ...

Pierre.

Offline


Just remove the code from  {form_field field="state"} to {/form_field}


OpenStudio Toulouse

Offline


Hi,
I think I'm misunderstanding or I didn't make myself clear. I do not want to suppress the state field, I want to make it "not required". My original question was "how do I make this field as not required without suppressing it ?" ... What you just suggested is completely removing that field, am I correct ?if yes, how do I make it not required ?
Pierre

Offline


I was not totally clear : if states are attached to a country (e.g.; USA), the state field is required. For countries without attached states, the field is not required.

This behaviour is defined in \Thelia\Form\AddressCountryValidationTrait::verifyState() method.


OpenStudio Toulouse

Offline


Hello,
Ok I understand now what you meant and it's really what's needed ... but that means also that it does not work (for me at least), in my register page, whatever I select as a country, the field is required. For example if I go directly to the /register page, France is selected and Etat/Region is marked as required with a star. But I will test more in depth now that I know about how it is supposed to work and I will report back here.
Thanks !
Pierre.

Offline


Hello,
Ok I made some more tests and if I choose France I can submit the form without choosing a state which is the proper way I think. The only small problem is that "State" still has a "*" meaning it's mandatory ...
From what I read in the code,  "*" should be only if the $required variable exists:

{if $required} <span class="required">*</span>{/if}

But does not look like it's working here ... at the same time I do not see how a smarty test on a variable could work for something that is changing in the page with a nearby select ... only javascript coud work but maybe I'm misunderstanding something here.
I have the feeling something is not working properly, maybe there is a required hook I'm missing ? there does not seem to be a relationship between country and state, I can validate Gabon+Arkansas no problem ...
Pierre

Offline


Hello,

Ok I did find the problem. I derived my templates from the "Zeste" template which might be too old to have integrated the needed js ... I copied the necessary js (at least my analysis was right on spot) and now it works as intented :-)
Yeepee.

Pierre.