Jump to content

How to add default values in renderform()


dwojod
 Share

Recommended Posts

Hi,

 

I decided create module:)

And i try add to default vaules in text field in controller module

 

array(
                    'type' => 'text',
                    'label' => $this->l('Vocher:'),
                    'name' => 'nr_voucher',
                    'disabled' => true,
                    'desc' => $this->l('Automatic generate code'),
                    'value'=> 'test',
                ),
 
this solution not working
 
generally i want to add in 'values' function results, which generate random string
 
 

Share this post


Link to post
Share on other sites

ok, I know what you mean but:

 

it will be grerat if I can implement that functions like in AdminCartRules -> generate code in js

 

but it will be impossiblle, I want to create some random string in PHP, and when actions is 'add', display in this field

 

i need some help 

 

regards

Share this post


Link to post
Share on other sites

ok, I find solution

 

I focus on file mymodule/views/templates/admin/mymodule/helpers/form/form.tpl and I add piece of code,

button with id="bt_" generate random string, I use jQuery function in this same file

{extends file="helpers/form/form.tpl"}

{block name="input"}
    {if $input.name == 'nr_voucher'}
        <div class="row">
            <div class="input-group col-lg-4">
                <input
                        id="{if isset($input.id)}{$input.id}{else}{$input.name}{/if}"
                        type="text"
                        name="{$input.name}"
                        value="{$fields_value[$input.name]|escape:'html':'UTF-8'}" />
				<span class="input-group-addon">
					<i class="icon-puzzle-piece"></i>
				</span>
				<span class="input-group-btn">
					<a id="bt_" class="btn btn-default"><i class="icon-random"></i>{l s='Generate'}</a>
				</span>
            </div>
        </div>
    {else}
        {$smarty.block.parent}
    {/if}
{/block}
{block name=script}
    {* Add your scripts here *}
	
	...
{/block}

Share this post


Link to post
Share on other sites

  • 6 years later...

Solution tested in PS version= 1.7.7 , in your module controller extended of ModuleAdminController :

public function renderForm()
{        
    //....fields definitons 
    $this->fields_form = array(...);
	
    // Set or create properties values of 'object' to establish default values 
    $this->object->nr_vouche = someLogicOrValue()  ; //  nr_vouche is defined in $this->fields_form
   
    $this->object->other_defined_field = = someLogicOrValue() ;
   
    return parent::renderForm();


}

 

Explanation:  see  the behavior in classes/controller/AdminController.php , method  renderForm(), when calls $this->getFieldsValue($this->object); 

 

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More