Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

Prestashop, default value radio box

I am on a prestashop 1.7.6.5 and I would like to switch to a radio box with a default value. This is in the billing address form and the file should be form-field.tpl. This is civility (Mr / Mrs) and you should set Mr by default. How to do ?

The code :

{if $field.type == 'hidden'}
{block name='form_field_item_hidden'}
 <input type="hidden" name="{$field.name}" value="{$field.value}">
{/block}
{else}
<div class="form-group row align-items-center {if !empty($field.errors)}has-error{/if}">
<label class="col-md-2 col-form-label{if $field.required} required{/if}">
  {if $field.type !== 'checkbox'}
    {$field.label}
  {/if}
</label>
<div class="col-md-8{if ($field.type === 'radio-buttons')} form-control-valign{/if}">

  {if $field.type === 'select'}

    {block name='form_field_item_select'}
        <div class="custom-select2">
            <select class="form-control form-control-select" name="{$field.name}" {if $field.required}required{/if}>
                <option value disabled selected>{l s='-- please choose --' d='Shop.Forms.Labels'}</option>
                {foreach from=$field.availableValues item="label" key="value"}
                    <option value="{$value}" {if $value eq $field.value} selected {/if}>{$label}</option>
                {/foreach}
            </select>
        </div>
    {/block}

  {elseif $field.type === 'countrySelect'}

    {block name='form_field_item_country'}
      <div class="custom-select2">
        <select class="form-control form-control-select js-country" name="{$field.name}"
        {if $field.required}required{/if}>
            <option value disabled selected>{l s='-- please choose --' d='Shop.Forms.Labels'}</option>
            {foreach from=$field.availableValues item="label" key="value"}
                <option value="{$value}" {if $value eq $field.value} selected {/if}>{$label}</option>
            {/foreach}
        </select>
      </div>
    {/block}

  {elseif $field.type === 'radio-buttons'}

    {block name='form_field_item_radio'}
      {foreach from=$field.availableValues item="label" key="value"}
        <label class="radio-inline">
          <span class="custom-radio">
            <input
              name="{$field.name}"
              type="radio"
              value="{$value}"
              {if $field.required}required{/if}
              {if $value eq $field.value} checked {/if}
            >
            <span></span>
          </span>
          {$label}
        </label>
      {/foreach}
    {/block}

  {elseif $field.type === 'checkbox'}

    {block name='form_field_item_checkbox'}
      <span class="custom-checkbox">
        <input name="{$field.name}" id="ff_{$field.name}" type="checkbox" value="1" {if $field.value}checked="checked"{/if} {if $field.required}required{/if}>
        <span><i class="fa fa-check rtl-no-flip checkbox-checked" aria-hidden="true"></i></span>
        <label for="ff_{$field.name}">{$field.label nofilter}</label >
      </span>
    {/block}

  {elseif $field.type === 'date'}

    {block name='form_field_item_date'}
      <input name="{$field.name}" class="form-control" type="date" value="{$field.value}" placeholder="{if isset($field.availableValues.placeholder)}{$field.availableValues.placeholder}{/if}">
      {if isset($field.availableValues.comment)}
        <span class="form-control-comment">
          {$field.availableValues.comment}
        </span>
      {/if}
    {/block}

  {elseif $field.type === 'birthday'}

    {block name='form_field_item_birthday'}
      <div class="js-parent-focus">
        {html_select_date
        field_order=DMY
        time={$field.value}
        field_array={$field.name}
        prefix=false
        reverse_years=true
        field_separator='<br>'
        day_extra='class="form-control form-control-select"'
        month_extra='class="form-control form-control-select"'
        year_extra='class="form-control form-control-select"'
        day_empty={l s='-- day --' d='Shop.Forms.Labels'}
        month_empty={l s='-- month --' d='Shop.Forms.Labels'}
        year_empty={l s='-- year --' d='Shop.Forms.Labels'}
        start_year={'Y'|date}-100 end_year={'Y'|date}
        }
      </div>
    {/block}

  {elseif $field.type === 'password'}

    {block name='form_field_item_password'}
      <div class="input-group js-parent-focus">
        <input
          class="form-control js-child-focus js-visible-password"
          name="{$field.name}"
          title="{l s='At least 5 characters long' d='Shop.Forms.Help'}"
          {if isset($wishlistModal)}autocomplete="new-password"{/if}
          type="password"
          value=""
          pattern=".{literal}{{/literal}5,{literal}}{/literal}"
          {if $field.required}required{/if}
        >
        <span class="input-group-append">
          <button
            class="btn btn-outline-secondary"
            type="button"
            data-action="show-password"
          >
           <i class="fa fa-eye-slash" aria-hidden="true"></i>
          </button>
        </span>
      </div>
    {/block}

  {else}

    {block name='form_field_item_other'}
      <input
        class="form-control"
        name="{$field.name}"
        type="{$field.type}"
        value="{$field.value}"
        {if isset($field.availableValues.placeholder)}placeholder="{$field.availableValues.placeholder}"{/if}
        {if $field.maxLength}maxlength="{$field.maxLength}"{/if}
        {if $field.required}required{/if}
      >
      {if isset($field.availableValues.comment)}
        <span class="form-control-comment">
          {$field.availableValues.comment}
        </span>
      {/if}
    {/block}

  {/if}

  {block name='form_field_errors'}
    {include file='_partials/form-errors.tpl' errors=$field.errors}
  {/block}

</div>

<div class="col-md-2 form-control-comment">
  {block name='form_field_comment'}
    {if (!$field.required && !in_array($field.type, ['radio-buttons', 'checkbox']))}
     {l s='Optional' d='Shop.Forms.Labels'}
    {/if}
  {/block}
</div>

{/if}

Then, on Iphone, the necessary does not work. Thank you for the help you could give me.

question from:https://stackoverflow.com/questions/65898723/prestashop-default-value-radio-box

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...