onblur function call in zend framework add element - zend-framework

I am new to fend framework. I have a input box in html with on blur property which call a ajax function code is given below:
input name="companyCode" type="text" id="companyCode" style="width:220px"
onblur="getOrganizationode(this.value);"
and a ajax script tags.
Basically i want my input box in Zend form with onblur function call in Add element function like this
addElement( 'text', 'companyCode' , array(
'required' => true,
'filters' => array('StringTrim'),
'style' => array('width:220px'),
so please help me

You can just add the call to the attributes:
addElement('text', 'companyCode', array(
'required' => true,
'filters' => array('StringTrim'),
'style' => array('width:220px'),
'onBlur' => 'getOrganizationode(this.value);'
);

Related

Propel form type model w. group_by is rendered without property display

Env: Symfony2 2.7 / Propel 1.6
I've created a choice form type like that:
$builder->add('mychoice', 'model', array(
'class' => 'Foo\\Bar',
'query' => FooBarQuery::create()->filterBySomething(true),
'group_by' => 'example',
'property' => 'title',
'multiple' => false,
'expanded' => false,
));
The rendering choice list is ok with good optgroup select options but the title's property is not displayed - id's property instead. If I remove the group_by option, the title property is well displayed.
What's wrong?
Would this work?
$builder->add(
'mychoice',
'entity',
array(
'class' => 'Foo\\Bar',
'choice_label' => 'title',
'multiple' => false,
'expanded' => false,
)
);
Set the type to entity and add a choice_label property and the property you want to be displayed.

zend addElements form onchange select

I try to add dinamically a form input Elemnt on onchange of select element.
I have this code:
$this->addElement('select', 'nationality', array(
'multiOptions' => array('CH' => 'Choose','IT' => 'Italy', 'other' => 'Other'),
'required' => true,
'label' => 'Nation',
'filters' => array('StringTrim'),
'onChange' => '???'
));
I try to paste my new element instead "???"
$this->addElement('select', 'nationality', array(
'multiOptions' => array('CH' => 'Choose','IT' => 'Italy', 'other' => 'Other'),
'required' => true,
'label' => 'Nation',
'filters' => array('StringTrim'),
'onChange' => '$this->addElement(
'text', 'codice_fiscale', array(
'required' => true,
'label' => 'Codice fiscale',
'required' => true
))'
));
I know is not correct, but I dont' found any documentation about it.
How can I add an element onchange select value?
Thanks in advance
I would approach the problem in a different way, if it's possible for you:
javascript functions to call on the onChange. It would be syntax correct (and, as you said, what you wrote is not correct, it's going to be printed out entirely on the onChange attribute, not interpreted through php).
so, i would write
'onChange' => 'addElement()'
and then declare the javascript function which handles new elements. Or, you can prepare the elements before (if you have a fixed number), and show / hide them. It may be convenient if you don't have much elements, but if they're too many, just add through javascript the needed one.
PseudoCode Javascript
function addElement()
{
// add your element here, or show / hide it
}
As far as I saw from my experience and similar cases
(Zend_form_element_select onchange in zend framework,
Zend Form: onchange select load another view content)
you won't escape from Javascript if you want to handle the "onChange"

How do I allow html tags in label for Zend form element using addElement()?

I am brand new to Zend and I've been given a project to make adjustments on. I'd like to add html to the labels for my form elements but I can't seem to get it right.
Here's what I have:
$this->addElement('text', 'school_name', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 150)),
),
'required' => true,
'label' => 'Name* :<img src="picture.png">,
'size' => '90',
));
As is, of course, the <img src="picture.png"> text gets escaped and the whole string is displayed.
I've read that I need to use 'escape' => false in some capacity but I can't figure out where/how to use it in my specific case.
Any help would be great. Thanks!
After calling addElement fetch the label's decorator and change the escape setting:
$form->getElement('school_name')->getDecorator('label')->setOption('escape', false);
If you use this type of label a lot, you should consider writing a custom decorator.
You can also use the disable_html_escape in 'label_options' when adding an element to the form:
$this->add(array(
....
'options' => array(
'label' => '<span class="required">Name</span>,
'label_options' => array(
'disable_html_escape' => true,
)
),
...
));
Credit to Théo Bouveret's post 'Button content in ZF2 forms' for the answer.

how to add decoratives in select box in zend framework Form

I am new to zend I want to add decoratives,size in my select box
example like this
'required' => true,
'filters' => array('StringTrim'),
'style' => array('width:103px'),
'multiOptions' => $list,
'decorators'=>Array(
'ViewHelper','Errors'
),
this is my code
$companyName = new Zend_Form_Element_Select('companyName');
$this->addElement($companyName);
Your question isn't very clear, but you can supply an array of options as the second parameter to the form element:
$companyName = new Zend_Form_Element_Select('companyName', array(
'required' => true,
'filters' => array('StringTrim')
));
$this->addElement($companyName);
This tutorial will help you
http://www.codexperience.co.za/post/creating-good-looking-zend-forms
Its all about styling your zend forms using the traditional way whilst retaining the awesomeness that Zend_Form comes with

Zend Framework Form Submit Button Style

Is it possible to change the form's Submit button from the defaut - like the Gmail button say, which is blue?
Currently I have this in my form:
$this->addElement('submit', 'form_element_signup', array('label' => 'Sign up',
'tabindex' => 20,
'decorators' => array('ViewHelper',
array(array('div' => 'HtmlTag'),
array ('tag' => 'button',
'class' => 'action blue')))));
But this still gives me the default submit button within my div button.
you can add your custom class with your own css property like below
$this->addElement(new Zend_Form_Element_Button( 'send',
array( 'label' => 'registrieren',
'class' => 'button-red',
'type' => 'submit',
'escape' => false,
'required' => false,
'ignore' => false, ) ));
Yes just apply the appropriate CSS to the 'div', 'tag' or 'class' as required.
22 CSS Button Styling Tutorials and Techniques may help.