/** * Create an jForms control object based on a qgis edit widget. * And add it to the passed form. * @param string $ref Name of the control. * @param object $edittype simplexml object corresponding to the QGIS edittype for this field. * @param object $aliasXml simplexml object corresponding to the QGIS alias for this field. * @param object $rendererCategories simplexml object corresponding to the QGIS categories of the renderer. * @param object $prop Jelix object with field properties (datatype, required, etc.) */ public function __construct($ref, $edittype, $aliasXml = Null, $rendererCategories = Null, $prop) { // Add new editTypes naming convention since QGIS 2.4 $this->qgisEdittypeMap['LineEdit'] = $this->qgisEdittypeMap[0]; $this->qgisEdittypeMap['UniqueValues'] = $this->qgisEdittypeMap[2]; $this->qgisEdittypeMap['UniqueValuesEditable'] = $this->qgisEdittypeMap[2]; $this->qgisEdittypeMap['ValueMap'] = $this->qgisEdittypeMap[3]; $this->qgisEdittypeMap['Classification'] = $this->qgisEdittypeMap[4]; $this->qgisEdittypeMap['EditRange'] = $this->qgisEdittypeMap[5]; $this->qgisEdittypeMap['SliderRange'] = $this->qgisEdittypeMap[5]; $this->qgisEdittypeMap['CheckBox'] = $this->qgisEdittypeMap[7]; $this->qgisEdittypeMap['FileName'] = $this->qgisEdittypeMap[8]; $this->qgisEdittypeMap['Enumeration'] = $this->qgisEdittypeMap[-1]; $this->qgisEdittypeMap['Immutable'] = $this->qgisEdittypeMap[10]; $this->qgisEdittypeMap['Hidden'] = $this->qgisEdittypeMap[11]; $this->qgisEdittypeMap['TextEdit'] = $this->qgisEdittypeMap[12]; $this->qgisEdittypeMap['Calendar'] = $this->qgisEdittypeMap[13]; $this->qgisEdittypeMap['DateTime'] = $this->qgisEdittypeMap[13]; $this->qgisEdittypeMap['DialRange'] = $this->qgisEdittypeMap[5]; $this->qgisEdittypeMap['ValueRelation'] = $this->qgisEdittypeMap[15]; $this->qgisEdittypeMap['UuidGenerator'] = $this->qgisEdittypeMap[16]; $this->qgisEdittypeMap['Photo'] = $this->qgisEdittypeMap[8]; $this->qgisEdittypeMap['WebView'] = $this->qgisEdittypeMap[0]; $this->qgisEdittypeMap['Color'] = $this->qgisEdittypeMap[0]; // Set class attributes $this->ref = $ref; $this->fieldName = $ref; if ($aliasXml and $aliasXml[0]) { $this->fieldAlias = (string) $aliasXml[0]->attributes()->name; } $this->fieldDataType = $this->castDataType[strtolower($prop->type)]; if ($prop->notNull && !$prop->autoIncrement) { $this->required = True; } if ($this->fieldDataType != 'geometry') { $this->edittype = $edittype; $this->rendererCategories = $rendererCategories; // Get qgis edittype data if ($this->edittype) { // New QGIS 2.4 edittypes : use widgetv2type property if (property_exists($this->edittype[0]->attributes(), 'widgetv2type')) { $this->fieldEditType = (string) $this->edittype[0]->attributes()->widgetv2type; // no more line edit. Since 2.4, textedit with multiline attribute = 0 if ((string) $this->edittype[0]->widgetv2config->attributes()->IsMultiline == '0') { $this->fieldEditType = 0; } } else { $this->fieldEditType = (int) $this->edittype[0]->attributes()->type; } } else { $this->fieldEditType = 0; } // Get jform control type if ($this->fieldEditType == 15) { $markup = $this->qgisEdittypeMap[$this->fieldEditType]['jform']['markup'][(int) $this->edittype[0]->attributes()->allowMulti]; } else { if ($this->fieldEditType === 'ValueRelation') { $markup = $this->qgisEdittypeMap[$this->fieldEditType]['jform']['markup'][(int) $this->edittype[0]->widgetv2config->attributes()->AllowMulti]; } else { $markup = $this->qgisEdittypeMap[$this->fieldEditType]['jform']['markup']; } } } else { $markup = 'hidden'; } // Create the control switch ($markup) { case 'input': $this->ctrl = new jFormsControlInput($this->ref); break; case 'menulist': $this->ctrl = new jFormsControlMenulist($this->ref); $this->fillControlDatasource(); break; case 'checkboxes': $this->ctrl = new jFormsControlCheckboxes($this->ref); $this->fillControlDatasource(); break; case 'hidden': $this->ctrl = new jFormsControlHidden($this->ref); break; case 'checkbox': $this->ctrl = new jFormsControlCheckbox($this->ref); $this->fillCheckboxValues(); break; case 'textarea': $this->ctrl = new jFormsControlTextarea($this->ref); break; case 'date': $this->ctrl = new jFormsControlDate($this->ref); break; case 'upload': $choice = new jFormsControlChoice($this->ref . '_choice'); $choice->createItem('keep', 'keep'); $choice->createItem('update', 'update'); $upload = new jFormsControlUpload($this->ref); if ($this->fieldEditType == 'Photo') { $upload->mimetype = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/gif'); $upload->accept = 'image/*'; $upload->capture = 'camera'; } $choice->addChildControl($upload, 'update'); $choice->createItem('delete', 'delete'); $choice->defaultValue = 'keep'; $this->ctrl = $choice; break; default: $this->ctrl = new jFormsControlInput($this->ref); break; } // Set control main properties $this->setControlMainProperties(); }
function testChoice() { /* <choice ref="choice"> <item value="item1"><label>labelitem1</label> <input ref="nom" /> <checkboxes ref="categories" required="true" /> </item> <item value="item2"><label>labelitem2</label> <input ref="datenaissance" type="date" /> </item> <item value="item3"><label>labelitem3</label> </item> </choice> */ $choice = new jFormsControlChoice('choice'); $choice->required = false; $choice->createItem('item1', 'labelitem1'); $choice->createItem('item2', 'labelitem2'); $choice->createItem('item3', 'labelitem3'); $ctrl = new jFormsControlInput('nom'); $ctrl->required = false; $choice->addChildControl($ctrl, 'item1'); $ctrl = new jFormsControlCheckboxes('categories'); $ctrl->required = true; $choice->addChildControl($ctrl, 'item1'); $ctrl = new jFormsControlinput('datenaissance'); $ctrl->datatype = new jDatatypelocaledate(); $choice->addChildControl($ctrl, 'item2'); $this->form->addCtrl($choice); $this->assertTrue($this->form->check()); // test if required work on the whole control $choice->required = true; $this->assertFalse($this->form->check()); // test if a bad value on choice trig a bad check $this->form->setData('choice', 'foo'); $this->assertFalse($this->form->check()); // test if a good value on choice trig a good check $this->form->setData('choice', 'item3'); $this->assertTrue($this->form->check()); // test if a good value on choice, with missing value on // an item control, trig a bad check $this->form->setData('choice', 'item1'); $this->assertFalse($this->form->check()); // test if a good value on choice, with a bad value on // an item control, trig a bad check $this->form->setData('categories', 'toto'); $this->assertFalse($this->form->check()); // test if a good value on choice, with a bad value on // a deactivated item control, trig a good check $this->form->setData('categories', 'toto'); $this->form->deactivate('categories'); $this->assertTrue($this->form->check()); // test if a good value on choice, with a good value on // an item control, trig a good check $this->form->setData('categories', array('toto')); $this->assertTrue($this->form->check()); $this->form->setData('categories', array('toto', 'titi')); $this->assertTrue($this->form->check()); // test if a good value on choice, with a missing value on // a non required item control, trig a good check $this->form->setData('choice', 'item2'); $this->assertTrue($this->form->check()); // test if a good value on choice, with a bad value on // an item control other than the selected control, trig a good check $this->form->setData('categories', ''); $this->assertTrue($this->form->check()); // test if a value corresponding to a deactivated item, trig a bad check $choice->deactivateItem('item2'); $this->form->setData('choice', 'item2'); $this->assertFalse($this->form->check()); }
function testChoice() { /* <choice ref="choice"> <item value="item1"><label>labelitem1</label> <input ref="nom" /> <checkboxes ref="categories" required="true" /> </item> <item value="item2"><label>labelitem2</label> <input ref="datenaissance" type="date" /> </item> <item value="item3"><label>labelitem3</label> </item> </choice> */ $choice = new jFormsControlChoice('choice'); $choice->required = false; $choice->createItem('item1', 'labelitem1'); $choice->createItem('item2', 'labelitem2'); $choice->createItem('item3', 'labelitem3'); $ctrl = new jFormsControlInput('nom'); $ctrl->required = false; $choice->addChildControl($ctrl, 'item1'); $ctrl = new jFormsControlCheckboxes('categories'); $ctrl->required = true; $choice->addChildControl($ctrl, 'item1'); $ctrl = new jFormsControlinput('datenaissance'); $ctrl->datatype = new jDatatypelocaledate(); $choice->addChildControl($ctrl, 'item2'); $this->form->addControl($choice); $origdata = $this->container->data; // prepare the request global $gJCoord; // check values in the container when the third item is selected $gJCoord->request->params = array('choice' => 'item3', 'nom' => 'dupont', 'categories' => array('foo', 'bar'), 'datenaissance' => '2000-01-01'); $this->form->initFromRequest(); $this->assertEquals('item3', $this->container->data['choice']); $this->assertEquals('', $this->container->data['nom']); $this->assertEquals(array(), $this->container->data['categories']); $this->assertEquals('', $this->container->data['datenaissance']); // check values in the container when the second item is selected $this->container->data = $origdata; $gJCoord->request->params = array('choice' => 'item2', 'nom' => 'dupont', 'categories' => array('foo', 'bar'), 'datenaissance' => '2000-01-01'); $this->form->initFromRequest(); $this->assertEquals('item2', $this->container->data['choice']); $this->assertEquals('', $this->container->data['nom']); $this->assertEquals(array(), $this->container->data['categories']); $this->assertEquals('2000-01-01', $this->container->data['datenaissance']); // check values in the container when the first item is selected $this->container->data = $origdata; $gJCoord->request->params = array('choice' => 'item1', 'nom' => 'dupont', 'categories' => array('foo', 'bar'), 'datenaissance' => '2000-01-01'); $this->form->initFromRequest(); $this->assertEquals('item1', $this->container->data['choice']); $this->assertEquals('dupont', $this->container->data['nom']); $this->assertEquals(array('foo', 'bar'), $this->container->data['categories']); $this->assertEquals('', $this->container->data['datenaissance']); // let's deactivate an item $this->container->data = $origdata; $choice->deactivateItem('item1'); $gJCoord->request->params = array('choice' => 'item1', 'nom' => 'dupont', 'categories' => array('foo', 'bar'), 'datenaissance' => '2000-01-01'); $this->form->initFromRequest(); $this->assertEquals('', $this->container->data['choice']); $this->assertEquals('', $this->container->data['nom']); $this->assertEquals(array(), $this->container->data['categories']); $this->assertEquals('', $this->container->data['datenaissance']); }
function testOutputChoice() { /* <choice ref="status"> <label>Task Status</label <item value="new"><label>New</label> </item> <item value="assigned"><label>Assigned</label> <input ref="nom" required="true"><label>Name</label></input> <input ref="prenom" required="true"><label>Firstname</label></input> </item> <item value="closed"><label>Closed</label> <menulist ref="reason" required="true"> <label>Reason</label> <item value="aa">fixed</item> <item value="bb">won t fixed</item> <item value="cc">later</item> <alert type="required">Hey, specify a reason !</alert> </menulist> </item> </choice> */ $choice = new jFormsControlChoice('status'); $choice->label = 'Task Status'; $choice->createItem('new', 'New'); $choice->createItem('assigned', 'Assigned'); $choice->createItem('closed', 'Closed'); $ctrlnom = new jFormsControlinput('nom'); $ctrlnom->required = true; $ctrlnom->label = 'Name'; $choice->addChildControl($ctrlnom, 'assigned'); $ctrlprenom = new jFormsControlinput('prenom'); $ctrlprenom->defaultValue = 'robert'; $ctrlprenom->label = 'Firstname'; $choice->addChildControl($ctrlprenom, 'assigned'); $ctrlreason = new jFormsControlMenulist('reason'); $ctrlreason->required = true; $ctrlreason->label = 'Reason '; $ctrlreason->alertRequired = 'Hey, specify a reason !'; $ctrlreason->datasource = new jFormsStaticDatasource(); $ctrlreason->datasource->data = array('aa' => 'fixed', 'bb' => 'won t fixed', 'cc' => 'later'); $choice->addChildControl($ctrlreason, 'closed'); $this->form->addControl($choice); $choice->setReadOnly(false); // output of the label of <choice> ob_start(); $this->builder->outputControlLabel($choice); $out = ob_get_clean(); $this->assertEqualOrDiff('<span class="jforms-label" id="' . $this->formname . '_status_label">Task Status</span>' . "\n", $out); // ouput of the whole <choice>, with original values $expected = '<ul class="jforms-choice jforms-ctl-status" >' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_0" type="radio" value="new" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>' . "\n" . '</li>' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_1" type="radio" value="assigned" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="' . $this->formname . '_nom" id="' . $this->formname . '_nom_label">Name<span class="jforms-required-star">*</span></label>' . "\n" . ' <input name="nom" id="' . $this->formname . '_nom" class="jforms-ctrl-input jforms-required" value="" type="text"/>' . "\n" . '</span>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="' . $this->formname . '_prenom" id="' . $this->formname . '_prenom_label">Firstname</label>' . "\n" . ' <input name="prenom" id="' . $this->formname . '_prenom" class="jforms-ctrl-input" value="robert" type="text"/>' . "\n" . '</span>' . "\n"; $expected .= '</li>' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_2" type="radio" value="closed" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="' . $this->formname . '_reason" id="' . $this->formname . '_reason_label">Reason <span class="jforms-required-star">*</span></label>' . "\n"; $expected .= ' <select name="reason" id="' . $this->formname . '_reason" class="jforms-ctrl-menulist jforms-required" size="1">' . "\n" . '<option value="" selected="selected"></option>' . "\n" . '<option value="aa">fixed</option>' . "\n" . '<option value="bb">won t fixed</option>' . "\n" . '<option value="cc">later</option>' . "\n" . '</select>' . "\n" . '</span>' . "\n"; $expected .= '</li>' . "\n"; $expected .= '</ul>' . "\n\n"; ob_start(); $this->builder->outputControl($choice); $out = ob_get_clean(); $this->assertEqualOrDiff($expected, $out); $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\'); c.errInvalid=\'"Task Status" field is invalid\'; jFormsJQ.tForm.addControl(c); c2 = c; c2.items[\'new\']=[]; c = new jFormsJQControlString(\'nom\', \'Name\'); c.required = true; c.errRequired=\'"Name" field is required\'; c.errInvalid=\'"Name" field is invalid\'; c2.addControl(c, \'assigned\'); c = new jFormsJQControlString(\'prenom\', \'Firstname\'); c.errInvalid=\'"Firstname" field is invalid\'; c2.addControl(c, \'assigned\'); c = new jFormsJQControlString(\'reason\', \'Reason \'); c.required = true; c.errRequired=\'Hey, specify a reason !\'; c.errInvalid=\'"Reason " field is invalid\'; c2.addControl(c, \'closed\'); c2.activate(\'\'); ', $this->builder->getJsContent()); // ouput of the whole <choice>, with the first item selected $this->form->getContainer()->data['status'] = 'assigned'; $expected = '<ul class="jforms-choice jforms-ctl-status" >' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_0" type="radio" value="new" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>' . "\n" . '</li>' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_1" type="radio" value="assigned" checked="checked" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="' . $this->formname . '_nom" id="' . $this->formname . '_nom_label">Name<span class="jforms-required-star">*</span></label>' . "\n" . ' <input name="nom" id="' . $this->formname . '_nom" class="jforms-ctrl-input jforms-required" value="" type="text"/>' . "\n" . '</span>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="' . $this->formname . '_prenom" id="' . $this->formname . '_prenom_label">Firstname</label>' . "\n" . ' <input name="prenom" id="' . $this->formname . '_prenom" class="jforms-ctrl-input" value="robert" type="text"/>' . "\n" . '</span>' . "\n"; $expected .= '</li>' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_2" type="radio" value="closed" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="' . $this->formname . '_reason" id="' . $this->formname . '_reason_label">Reason <span class="jforms-required-star">*</span></label>' . "\n"; $expected .= ' <select name="reason" id="' . $this->formname . '_reason" class="jforms-ctrl-menulist jforms-required" size="1">' . "\n" . '<option value="" selected="selected"></option>' . "\n" . '<option value="aa">fixed</option>' . "\n" . '<option value="bb">won t fixed</option>' . "\n" . '<option value="cc">later</option>' . "\n" . '</select>' . "\n" . '</span>' . "\n"; $expected .= '</li>' . "\n"; $expected .= '</ul>' . "\n\n"; ob_start(); $this->builder->outputControl($choice); $out = ob_get_clean(); $this->assertEqualOrDiff($expected, $out); $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\'); c.errInvalid=\'"Task Status" field is invalid\'; jFormsJQ.tForm.addControl(c); c2 = c; c2.items[\'new\']=[]; c = new jFormsJQControlString(\'nom\', \'Name\'); c.required = true; c.errRequired=\'"Name" field is required\'; c.errInvalid=\'"Name" field is invalid\'; c2.addControl(c, \'assigned\'); c = new jFormsJQControlString(\'prenom\', \'Firstname\'); c.errInvalid=\'"Firstname" field is invalid\'; c2.addControl(c, \'assigned\'); c = new jFormsJQControlString(\'reason\', \'Reason \'); c.required = true; c.errRequired=\'Hey, specify a reason !\'; c.errInvalid=\'"Reason " field is invalid\'; c2.addControl(c, \'closed\'); c2.activate(\'assigned\'); ', $this->builder->getJsContent()); // ouput of the whole <choice>, with the second item selected $this->form->getContainer()->data['status'] = 'new'; $expected = '<ul class="jforms-choice jforms-ctl-status" >' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_0" type="radio" value="new" checked="checked" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>' . "\n" . '</li>' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_1" type="radio" value="assigned" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="' . $this->formname . '_nom" id="' . $this->formname . '_nom_label">Name<span class="jforms-required-star">*</span></label>' . "\n" . ' <input name="nom" id="' . $this->formname . '_nom" class="jforms-ctrl-input jforms-required" value="" type="text"/>' . "\n" . '</span>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="' . $this->formname . '_prenom" id="' . $this->formname . '_prenom_label">Firstname</label>' . "\n" . ' <input name="prenom" id="' . $this->formname . '_prenom" class="jforms-ctrl-input" value="robert" type="text"/>' . "\n" . '</span>' . "\n"; $expected .= '</li>' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_2" type="radio" value="closed" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="' . $this->formname . '_reason" id="' . $this->formname . '_reason_label">Reason <span class="jforms-required-star">*</span></label>' . "\n"; $expected .= ' <select name="reason" id="' . $this->formname . '_reason" class="jforms-ctrl-menulist jforms-required" size="1">' . "\n" . '<option value="" selected="selected"></option>' . "\n" . '<option value="aa">fixed</option>' . "\n" . '<option value="bb">won t fixed</option>' . "\n" . '<option value="cc">later</option>' . "\n" . '</select>' . "\n" . '</span>' . "\n"; $expected .= '</li>' . "\n"; $expected .= '</ul>' . "\n\n"; ob_start(); $this->builder->outputControl($choice); $out = ob_get_clean(); $this->assertEqualOrDiff($expected, $out); $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\'); c.errInvalid=\'"Task Status" field is invalid\'; jFormsJQ.tForm.addControl(c); c2 = c; c2.items[\'new\']=[]; c = new jFormsJQControlString(\'nom\', \'Name\'); c.required = true; c.errRequired=\'"Name" field is required\'; c.errInvalid=\'"Name" field is invalid\'; c2.addControl(c, \'assigned\'); c = new jFormsJQControlString(\'prenom\', \'Firstname\'); c.errInvalid=\'"Firstname" field is invalid\'; c2.addControl(c, \'assigned\'); c = new jFormsJQControlString(\'reason\', \'Reason \'); c.required = true; c.errRequired=\'Hey, specify a reason !\'; c.errInvalid=\'"Reason " field is invalid\'; c2.addControl(c, \'closed\'); c2.activate(\'new\'); ', $this->builder->getJsContent()); // ouput of the whole <choice>, with the third item selected $this->form->getContainer()->data['status'] = 'closed'; $expected = '<ul class="jforms-choice jforms-ctl-status" >' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_0" type="radio" value="new" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>' . "\n" . '</li>' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_1" type="radio" value="assigned" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="' . $this->formname . '_nom" id="' . $this->formname . '_nom_label">Name<span class="jforms-required-star">*</span></label>' . "\n" . ' <input name="nom" id="' . $this->formname . '_nom" class="jforms-ctrl-input jforms-required" value="" type="text"/>' . "\n" . '</span>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="' . $this->formname . '_prenom" id="' . $this->formname . '_prenom_label">Firstname</label>' . "\n" . ' <input name="prenom" id="' . $this->formname . '_prenom" class="jforms-ctrl-input" value="robert" type="text"/>' . "\n" . '</span>' . "\n"; $expected .= '</li>' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_2" type="radio" value="closed" checked="checked" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label jforms-required" for="' . $this->formname . '_reason" id="' . $this->formname . '_reason_label">Reason <span class="jforms-required-star">*</span></label>' . "\n"; $expected .= ' <select name="reason" id="' . $this->formname . '_reason" class="jforms-ctrl-menulist jforms-required" size="1">' . "\n" . '<option value="" selected="selected"></option>' . "\n" . '<option value="aa">fixed</option>' . "\n" . '<option value="bb">won t fixed</option>' . "\n" . '<option value="cc">later</option>' . "\n" . '</select>' . "\n" . '</span>' . "\n"; $expected .= '</li>' . "\n"; $expected .= '</ul>' . "\n\n"; ob_start(); $this->builder->outputControl($choice); $out = ob_get_clean(); $this->assertEqualOrDiff($expected, $out); $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\'); c.errInvalid=\'"Task Status" field is invalid\'; jFormsJQ.tForm.addControl(c); c2 = c; c2.items[\'new\']=[]; c = new jFormsJQControlString(\'nom\', \'Name\'); c.required = true; c.errRequired=\'"Name" field is required\'; c.errInvalid=\'"Name" field is invalid\'; c2.addControl(c, \'assigned\'); c = new jFormsJQControlString(\'prenom\', \'Firstname\'); c.errInvalid=\'"Firstname" field is invalid\'; c2.addControl(c, \'assigned\'); c = new jFormsJQControlString(\'reason\', \'Reason \'); c.required = true; c.errRequired=\'Hey, specify a reason !\'; c.errInvalid=\'"Reason " field is invalid\'; c2.addControl(c, \'closed\'); c2.activate(\'closed\'); ', $this->builder->getJsContent()); // ouput of the whole <choice>, in readonly mode, with the third item selected $choice->setReadOnly(true); $expected = '<ul class="jforms-choice jforms-ctl-status" >' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_0" readonly="readonly" type="radio" value="new" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>' . "\n" . '</li>' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_1" readonly="readonly" type="radio" value="assigned" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'assigned\')"/>Assigned</label>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="' . $this->formname . '_nom" id="' . $this->formname . '_nom_label">Name</label>' . "\n" . ' <input name="nom" id="' . $this->formname . '_nom" readonly="readonly" class="jforms-ctrl-input jforms-readonly" value="" type="text"/>' . "\n" . '</span>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="' . $this->formname . '_prenom" id="' . $this->formname . '_prenom_label">Firstname</label>' . "\n" . ' <input name="prenom" id="' . $this->formname . '_prenom" readonly="readonly" class="jforms-ctrl-input jforms-readonly" value="robert" type="text"/>' . "\n" . '</span>' . "\n"; $expected .= '</li>' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_2" readonly="readonly" type="radio" value="closed" checked="checked" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="' . $this->formname . '_reason" id="' . $this->formname . '_reason_label">Reason </label>' . "\n"; $expected .= ' <select name="reason" id="' . $this->formname . '_reason" class="jforms-ctrl-menulist jforms-readonly" size="1">' . "\n" . '<option value="" selected="selected"></option>' . "\n" . '<option value="aa">fixed</option>' . "\n" . '<option value="bb">won t fixed</option>' . "\n" . '<option value="cc">later</option>' . "\n" . '</select>' . "\n" . '</span>' . "\n"; $expected .= '</li>' . "\n"; $expected .= '</ul>' . "\n\n"; ob_start(); $this->builder->outputControl($choice); $out = ob_get_clean(); $this->assertEqualOrDiff($expected, $out); $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\'); c.errInvalid=\'"Task Status" field is invalid\'; jFormsJQ.tForm.addControl(c); c2 = c; c2.items[\'new\']=[]; c = new jFormsJQControlString(\'nom\', \'Name\'); c.required = true; c.errRequired=\'"Name" field is required\'; c.errInvalid=\'"Name" field is invalid\'; c2.addControl(c, \'assigned\'); c = new jFormsJQControlString(\'prenom\', \'Firstname\'); c.errInvalid=\'"Firstname" field is invalid\'; c2.addControl(c, \'assigned\'); c = new jFormsJQControlString(\'reason\', \'Reason \'); c.required = true; c.errRequired=\'Hey, specify a reason !\'; c.errInvalid=\'"Reason " field is invalid\'; c2.addControl(c, \'closed\'); c2.activate(\'closed\'); ', $this->builder->getJsContent()); // ouput of the <choice>, with a deactivated item $this->form->getContainer()->data['status'] = 'closed'; $choice->deactivateItem('assigned'); $expected = '<ul class="jforms-choice jforms-ctl-status" >' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_0" readonly="readonly" type="radio" value="new" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'new\')"/>New</label>' . "\n" . '</li>' . "\n"; $expected .= '<li><label><input name="status" id="' . $this->formname . '_status_1" readonly="readonly" type="radio" value="closed" checked="checked" onclick="jFormsJQ.getForm(\'\').getControl(\'status\').activate(\'closed\')"/>Closed</label>' . "\n"; $expected .= ' <span class="jforms-item-controls"><label class="jforms-label" for="' . $this->formname . '_reason" id="' . $this->formname . '_reason_label">Reason </label>' . "\n"; $expected .= ' <select name="reason" id="' . $this->formname . '_reason" class="jforms-ctrl-menulist jforms-readonly" size="1">' . "\n" . '<option value="" selected="selected"></option>' . "\n" . '<option value="aa">fixed</option>' . "\n" . '<option value="bb">won t fixed</option>' . "\n" . '<option value="cc">later</option>' . "\n" . '</select>' . "\n" . '</span>' . "\n"; $expected .= '</li>' . "\n"; $expected .= '</ul>' . "\n\n"; ob_start(); $this->builder->outputControl($choice); $out = ob_get_clean(); $this->assertEqualOrDiff($expected, $out); $this->assertEqualOrDiff('c = new jFormsJQControlChoice(\'status\', \'Task Status\'); c.errInvalid=\'"Task Status" field is invalid\'; jFormsJQ.tForm.addControl(c); c2 = c; c2.items[\'new\']=[]; c = new jFormsJQControlString(\'reason\', \'Reason \'); c.required = true; c.errRequired=\'Hey, specify a reason !\'; c.errInvalid=\'"Reason " field is invalid\'; c2.addControl(c, \'closed\'); c2.activate(\'closed\'); ', $this->builder->getJsContent()); }