Jump to content

How i can add attributes in input by CustomerFormatter


DARLEI FERNANDO ZILL

Recommended Posts

 
How can I insert an attribute (id) into the input (radio) of my form?
I tried some ways but I did not succeed, could anyone give me a tip?
 
My last attempt...:
 
CustomerFormatter.php: 

getFormat(){}


$doc_typeField = (new FormField)
            ->setName('doc_type')
            ->setType('radio-buttons')
            ->setLabel(
                $this->translator->trans(
                    'Tipo de Documento', [], 'Shop.Forms.Labels'
                )
            )
        ;


$doc_typeField->addAvailableValue(1, "Pessoa Física")->addAvailableValue('id', 'id_pf');
 
Link to comment
Share on other sites

I solved by creating an override of the CustomerFormatter class and treating the remainder in customer-form.tpl

 

override/classes/CustomerFormatter.php

public function getFormat()
    {
        $format = [];

        $format['id_customer'] = (new FormField)
            ->setName('id_customer')
            ->setType('hidden')
        ;
		
        $docField = (new FormField)
            ->setName('doc_type')
            ->setType('radio-buttons')
            ->setLabel(
                $this->translator->trans(
                    'Tipo de Cliente', [], 'Shop.Forms.Labels'
                )
            )
        ;
		$docField->addAvailableValue(1, "Pessoa Física");
		$docField->addAvailableValue(2, "Pessoa Jurídica");
        $format[$docField->getName()] = $docField;
		
		$format['cpf'] = (new FormField)
            ->setName('cpf')
            ->setLabel(
                $this->translator->trans(
                    'Número do CPF', [], 'Shop.Forms.Labels'
                )
            )
        ;
....

customer-form.tpl:

{foreach from=$formFields item="field"}
		{block "form_field"}
			{if $field.name === 'cpf'}
				<div class="form-group row" id="fieldCPF" style="display:none">
					<label class="col-md-3 form-control-label required">
						{$field.label}
					</label>
					<div class="col-md-6">
						<input
							class="form-control"
							name="{$field.name}"
							type="{$field.type}"
							value="{$field.value}"
							{if $field.required}required{/if}
						  >
					</div>
				</div>
			{elseif $field.name === 'cnpj' or $field.name === 'razaosocial' or $field.name==='rg_ie'}
.....

I solved by creating an override of the CustomerFormatter class and treating the remainder in customer-form.tpl

  • Like 1
Link to comment
Share on other sites

To block of radio-buttons:

{foreach from=$field.availableValues key=chave item=item}
					<div class="col-md-6 form-control-valign">
						<label class="radio-inline">
							<span class="custom-radio">
								<input 
									name = "doc_type" 
									type = "radio" 
									value = {$chave}
									id = {if $chave === 1} "id_pf" {else} "id_pj" {/if}
									onclick = {if $chave === 1} "mostra();mostrapj()" {else} "oculta();ocultapj()" {/if}
									{if $position eq "edit"} 
										disabled="true"
									{/if} 
									{if $chave eq $doc_type && $position eq "edit"}
										checked="checked"
									{/if}
								>
								<span></span>
							</span>
							{$item}
						</label>
					</div>
					{/foreach}
Edited by DARLEI FERNANDO ZILL (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...