ZendX_JQuery dialogContainer usage - forms

I'm aming to make use of the ZendX_JQuery dialogContainer view helper, in order to produce a modal window, were users can input specified information(for example send a message). I'm trying to use the dialogContainer view helper in this fashion.
First of, include the ZendX library in the applications library folder.
Secondly, include the following row in the initViewHelper method within the Bootstrap.php file
"$view->addHelperPath('ZendX/JQuery/View/Helper/', 'ZendX_JQuery_View_Helper');"
third, adding the following conditional enabling of js in the layout.phtml
"<?php if($this->jQuery()->isEnabled()){
$this->jQuery()->setLocalPath($this->baseUrl()
.'/js/jquery/js/jquery-1.4.2.min.js')
->setUiLocalPath($this->baseUrl()
.'/js/jquery/js/jquery-ui-1.8.custom.min.js')
->addStylesheet($this->baseUrl()
.'/js/jquery/css/ui-lightness/jquery-ui-1.8.custom.css');
echo $this->jQuery();
}
?>"
fourth, creating my Application_Form_JQueryForm extending ZendX_JQuery_Form
"<?php
class Application_Form_JQueryForm extends ZendX_JQuery_Form
{
private $form;
public function init()
{
$this->form = $this->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . '/index/index')
->setMethod('post');
$this->form->setDecorators(array(
'FormElements',
'Form',
array ('DialogContainer', array(
'id' => 'tabContainer',
'style' => 'width: 600px;',
'title' => 'Send a private message to Kalle',
'JQueryParams' => array(
'tabPosition' => 'top',
),
)),
));
$topic = new Zend_Form_Element_Text('topic');
$topic->setValue('topic')
->setRequired(true)
->setValidators(array('validators' => array(
'validator' => 'StringLength',
'options' => array(1,15)
)))
->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array('HtmlTag', array('tag' => 'dl'))));
$textarea = new Zend_Form_Element_Textarea('textarea');
$textarea->setValue('post a comment')
->setAttribs(array(
'rows' => 4,
'cols' => 20
))
->setRequired(true)
->setValidators(array('validators' => array(
'validator' => 'StringLength',
'options' => array(1,15)
)))
->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array('HtmlTag', array('tag' => 'dl'))));
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Send your comment')
->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array('Description', array('escape' => false, 'tag' => 'span')),
array('HtmlTag', array('tag' => 'dl'))))
->setDescription('or Cancel');
$this->form->addElements(array($topic, $textarea, $submit));
}
}"
This form is then instanciated in the controllers action method, and called in the view.
And so to the problem of mine, no matter what i try, in order to for instance set, the width of the dialogContainer or any other parameter (color, css, height, so on and so forth), this being in the JQueryForm's setDecorator part for the form, i can't seem to get any change whatsoever in the resulting modal when called in the view, any help in the proper direction would be greatly appreciated
Thanks in advance, Kalle Johansson

A late answer for sure - but lots of views - so figured I would answer. The parameters you want to set for the modal should be set from the JQueryParams array. So - for example:
$this->form->setDecorators(array(
'FormElements',
'Form',
array ('DialogContainer', array(
'id' => 'tabContainer',
'style' => 'width: 600px;',
'title' => 'Send a private message to Kalle',
'JQueryParams' => array(
'tabPosition' => 'top',
'width' => '600',
'height' => '450'
),
)),
));
You can find these param options on the jQuery UI site.
LK

Related

Zend_Form Decorators, css and displaygroups

I'm trying with DisplayGroups in my form. I'm sure it is a css understanding problem.
This is how my form looks like:
Now I would love to make it nicer:
How can I move the legend of the Displaygroup onto the border?
How can I make the distance smaller between my labels an the fields?
Here is my formclass:
$this->setName('Schwestern');
$this->setMethod('post');
$vorname=$this->addElement('TextBox','vorname',array(
'label' => 'Vorname:',
));
$nachname=$this->addElement('TextBox','nachname',array(
'label' => 'Nachname:',
));
$strasse=$this->addElement('TextBox','strasse',array(
'label' => 'Strasse:',
));
$plz=$this->addElement('TextBox','plz',array(
'label' => 'PLZ:',
));
$ort=$this->addElement('TextBox','ort',array(
'label' => 'Ort:',
));
$telefon=$this->addElement('TextBox','telefon',array(
'label' => 'Telefon:',
));
$handy=$this->addElement('TextBox','handy',array(
'label' => 'Handy:',
));
$email=$this->addElement('TextBox','email',array(
'label' => 'Email:',
));
$geburtsdatum = $this->addElement('DateTextBox','geburtsdatum',array(
'label' => 'Geburtsdatum:',
'datePattern' => 'dd-MM-yyyy'
));
$this->addDisplayGroup(array(
'vorname',
'nachname',
'strasse',
'plz',
'ort',
'geburtsdatum'
),'contact',array('legend' => 'Name und Anschrift'));
$contact = $this->getDisplayGroup('contact');
$contact->setDecorators(array(
'FormElements',
'Fieldset',
array('HtmlTag',array('tag'=>'div','style'=>'width:200px;;float:left;border-style:solid; margin:5px;padding:5px;border-width:1px;border-color: grey;'))
));
$this->addDisplayGroup(array('telefon','handy','email'), 'kontaktdaten',array('legend'=>'Kontaktdaten'));
$this->getDisplayGroup('kontaktdaten')->setDecorators(array(
'FormElements',
'Fieldset',
array('HtmlTag',array('tag'=>'div','style'=>'width:200px;;float:left;border-style:solid; margin:5px;padding:5px;border-width:1px;border-color: grey;'))
));
$this->setDecorators(array(
'FormElements',
array(array('data'=>'HtmlTag'),
array('tag'=>'table','cellspacing'=>'6')),
'DijitForm'
));
EDIT 22/10/2015:
HTML Output of this part of the form:
Before I tried to use the fieldsets I decorated my forms like this:
$vorname=$this->addElement('TextBox','vorname',array(
'label' => 'Vorname:',
));
$vorname->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array(array('data'=>'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'td')),
array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
));
So can I use the decorators, or what would be the best solution to get this form nicer like I described above?

how to set readonly property in zend form add element

Hi I am new in zend framework.
I want to set ready only property on input box in zend Form.
example as we do in html
<input type ="text" readonly="readonly" />
this is my zend code:
$this->addElement('text', 'name', array(
'label' => '',
'required' => true,
'filters' => array('StringTrim'),
'style' => array('width:338px'),
'autocomplete' => 'off',
'decorators'=>Array(
'ViewHelper',
'Errors',
),
help mee
Try this
$this->getElement('text')->setAttrib('readonly', 'readonly');
Try something like this:
$this->addElement('text','text_field',array('attribs' => array('readonly' => 'true')));
In ZF2 you can create a form by extending Zend\Form and then add form element in the constructor. there you can set the attributes as follows.
use Zend\Form\Form;
class MyForm extends Form {
public function __construct() {
$this->add(array(
'name' => 'name',
'type' => 'Text',
'attributes' => array(
'id' => 'name',
'class' => 'form-control',
'readonly' => TRUE,
),
'options' => array(
'label' => 'Name : '
)
));
}
}

Zend Framework: What is the right way of setting default decorators for Zend_Form elements

i currently set my default decorators for my Zend_Form using a class extending from Zend_Form ...
class Application_Form_Abstract extends Zend_Form {
...
function loadDefaultDecorators() {
if ($this->loadDefaultDecoratorsIsDisabled()) {
return $this;
}
// ... for elements
$decorators = $this->_elementDecorators;
if (empty($decorators)) {
$this->setElementDecorators(array(
'ViewHelper',
'Errors',
array('Description', array('tag' => 'p', 'escape' => false)),
'Label',
array('HtmlTag', array('tag' => 'p'))
));
but i soon realize that that way, i cannot define specific element decorators like
$this->addElement('textarea', 'bio', array(
'decorators' => array(
'ViewHelper',
'Errors',
array('Description', array('tag' => 'p', 'escape' => false)),
'Label',
array('HtmlTag', array('tag' => 'p')),
new Application_Form_Decorator_WmdPreview,
)
));
as they will be over-written by my custom loadDefaultDecorators() function. i wonder if there is any way i can set default decorators for element only if they have no set decorators
You can disable the default decorator for 'bio' element by adding a call to setDisableLoadDefaultDecorators()
$this->addElement('textarea', 'bio', array(
'disableLoadDefaultDecorators' => true,
'decorators' => array(
'ViewHelper',
'Errors',
array('Description', array('tag' => 'p', 'escape' => false)),
'Label',
array('HtmlTag', array('tag' => 'p')),
new Application_Form_Decorator_WmdPreview,
)
));
Also to you save you a headache, displaygroups cannot have the same name as any element that they contain

Table Decorators on Zend Framework Form

i created a form that it decorates as table form
its my code for decorates
$this->setElementDecorators(array(
'ViewHelper',
'Errors'
array(array('data'=>'HtmlTag'),
array('tag'=>'td','class'=>'element')),
array('Label',array('tag'=>'td')),
array(array('row'=>'HtmlTag'),array('tag'=>'tr')),
));
$this->setDecorators(array(
'FormElements',
array('HtmlTag',array('tag'=>'table')),
'Form'
));
it works correctly,
now i wana errors message decorates too
what do i change my code?
Here is a rather complex way of doing it. I have added classes to the decorators too so you can style them unlike your example.
// To be assigned at the beginning of your form class.
public $elementDecorators = array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'col2')),
array('Label', array('tag' => 'td','class'=>'taR')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr','class' => 'rowA')),
);
$this->addElement('ValidationTextBox', 'name', array(
'decorators' => $this->elementDecorators,
'validators' => array(
array('regex', false,'/^[a-zA-Z ]+$/')
),
'label' => $this->translator->translate ( 'Name' ) . ' : ',
'required' => true,
'trim' => true,
'propercase' => true,
'regExp' => '[a-zA-Z ]+',
'invalidMessage' => $this->translator->translate ( 'Name - Must be alpha numeric.' )
)
);
If you want to show all erros grouped in one place you should remove the Error decorator from each element and then add to you form the formErrors decorator. Here is an example from How to remove Zend Form error messages?
$form->setDecorators(array(
'FormElements',
new Zend_Form_Decorator_FormErrors(array
(
'ignoreSubForms' => true,
'markupElementLabelEnd' => '</b>',
'markupElementLabelStart' => '<b>',
'markupListEnd' => '</div>',
'markupListItemEnd' => '</span>',
'markupListItemStart' => '<span>',
'markupListStart' => '<div id="Form_Errors">'
)
),
'Form'
));

How do i remove the label decorator from a submit button

In my form i have this code;
// Add the submit button
$element = $this->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'Add new material'
));
$element->removeDecorator('label');
However the form still renders with the label element between the tags.
What am i doing wrong?
This worked for me:
$this->addElements(array(
new Zend_Form_Element_Submit('submit', array(
'label' => 'Save'
))
));
$element = $this->getElement('submit');
$element->removeDecorator('DtDdWrapper');
I did print_r($element); to find out what decorators exist for $element.
The function addElement returns a reference to the current form not to the last added element.
You could try this:
$form = new Zend_Form();
$form->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'Add new material'
));
$element = $form->getElement('submit');
$element->removeDecorator('label');
I think the argument to removeDecorator is case-sensitive. I.e., it should be "Label" # note the uppercase 'L'.
To overcome this nuisance I'm defining manually the decorators for my element...
$details->addElement('text', 'in_year', array(
'decorators'=>array(
'ViewHelper',
array('HtmlTag', array('tag' => 'span')),
)
));
You can of course define your own tags. In this example I only initialise the "ViewHelper" decorator. If I want to initialise the "Label" decorator I would do:
$details->addElement('text', 'in_year', array(
'decorators'=>array(
'ViewHelper',
'Label',
array('HtmlTag', array('tag' => 'span')),
),
'attribs' => array('class' => 'required validate-digits')
));
I hope this makes sense... :o)