/** * Returns the element's value * * @return mixed */ public function getValue() { $value = null; //Get the related form if (is_object($this->_form) === true) { $hasDefaultValue = Tag::hasValue($this->_name); if ($hasDefaultValue === false) { //Get the possible value for the widget $value = $this->_form->getValue($this->_name); } } //Assign the default value if there is no form available if (is_null($value) === true) { $value = $this->_value; } return $value; }
/** * Tests Form::render * * @issue 10398 * @author Serghei Iakovlev <*****@*****.**> * @since 2016-07-17 */ public function testCreatingElementsWithNameSimilarToTheFormMethods() { $this->specify('Form::render does not return expected result', function ($name) { $form = new Form(); $element = new Text($name); expect($element->getName())->equals($name); $form->add($element); expect($form->render($name))->equals(sprintf('<input type="text" id="%s" name="%s" />', $name, $name)); expect($form->getValue($name))->null(); expect($element->getValue())->null(); }, ['examples' => $this->nameLikeFormMethodsProvider()]); }
private function getArrayValue(array $matches) { $baseName = $matches[0]; $value = parent::getValue($baseName); foreach ($matches as $key => $match) { if ($key) { if (isset($value[$match])) { $value = $value[$match]; } else { return null; } } } return $value; }
/** * Tests clearing the Form Elements by using Form::bind * * @issue 11978 * @author Serghei Iakovlev <*****@*****.**> * @since 2016-10-01 * @param IntegrationTester $I */ public function clearFormElementsByUsingFormBind(IntegrationTester $I) { $name = new Text('sel_name'); $text = new Text('sel_text'); $form = new Form(); $form->add($name)->add($text); $entity = new MvcModel(); $I->assertNull(Tag::getValue('sel_name')); $I->assertNull($form->getValue('sel_name')); $I->assertNull($form->get('sel_name')->getValue()); $I->assertNull($name->getValue()); Tag::setDefault('sel_name', 'Please specify name'); $_POST = ['sel_name' => 'Some Name', 'sel_text' => 'Some Text']; $form->bind($_POST, $entity); $I->assertEquals('Some Name', $entity->getName()); $I->assertEquals('Some Text', $entity->getText()); $I->assertEquals('Some Name', $form->getValue('sel_name')); $I->assertEquals('Some Name', $form->get('sel_name')->getValue()); $I->assertEquals('Some Name', $name->getValue()); $I->assertEquals('Some Text', $form->getValue('sel_text')); $I->assertEquals('Some Text', $form->get('sel_text')->getValue()); $I->assertEquals('Some Text', $text->getValue()); $form->clear(['sel_name']); $I->assertNull(Tag::getValue('sel_name')); $I->assertNull($form->getValue('sel_name')); $I->assertNull($form->get('sel_name')->getValue()); $I->assertNull($name->getValue()); $I->assertEquals('Some Text', $form->getValue('sel_text')); $I->assertEquals('Some Text', $form->get('sel_text')->getValue()); $I->assertEquals('Some Text', $text->getValue()); $form->clear(['non_existent', 'another_filed']); $I->assertEquals('Some Text', $form->getValue('sel_text')); $I->assertEquals('Some Text', $form->get('sel_text')->getValue()); $I->assertEquals('Some Text', $text->getValue()); $form->clear(); $I->assertNull(Tag::getValue('sel_text')); $I->assertNull($form->getValue('sel_text')); $I->assertNull($form->get('sel_text')->getValue()); $I->assertNull($text->getValue()); $I->assertEquals('Some Name', $entity->getName()); $I->assertEquals('Some Text', $entity->getText()); $I->assertEquals(['sel_name' => 'Some Name', 'sel_text' => 'Some Text'], $_POST); }