-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFR] Set the options for form elements #542
Comments
Is this the same as #535? |
No, it's not the same thing. Attributes relate directly to the tag of the element. $element = new \Phalcon\Forms\Element\Text('name');
$element->setAttribute('tooltip', 'This field is required'); Then get:
I need a method getAttribute in particular for the formation of the label:
|
This is implemented in 1.1.0, thanks |
@nikolasha can we choose another name for 'options', this is because Phalcon\Forms\Element\Select already implements this option to set the select's html options and this could confuse users in the future... |
Yes, I've thought about it. For the select element better to rename the property "options" in the "optionValues" and the methods of the setOptionValues and getOptionValues. But since you are, unfortunately, are afraid to change the API ;), then additional options can be given a name, for example, "customOptions". |
And do propose refactoring the component forms: namespace Phalcon\Forms;
abstract class Element
{
/**
* @deprecated Here is quite unnecessary
*/
protected $_form;
/**
* @deprecated It is better to keep in the array of attributes
*/
protected $_name;
/**
* @deprecated It is better to keep in the array of options
*/
protected $_label;
protected $_attributes;
protected $_validators;
/**
* Error messages should be attached to the element, not the form.
* Now, to get the message for a particular element has to make a strange loop:
* <?php
* $messages = $element->getForm()->getMessagesFor($element->getName());
* // must be:
* $messages = $element->getMessages();
* ?>
*/
protected $_messages;
/**
* @var array custom options
*/
protected $_options = array();
/**
* Value must be stored in the element.
* Use for this purpose "Phalcon\Tag::setDefault()" is a monstrous magic voodoo ;)
* By the way, "Phalcon\Tag" in general turned into a class-dump
*/
protected $_value;
/**
* @param string|array $name the element name or configuration
* @param string $label
* @param array $attributes
*/
public function __construct($name, $label = null, $attributes=null)
{
if (is_array($name)) {
$config = $name;
$name = $config['name']);
if (isset($config['label']) {
$label = $config['label']);
}
if (isset($config['attributes']) {
$attributes = $config['attributes']);
}
if (isset($config['options'])) {
$this->setOptions($config['options']);
}
}
// ...
}
public function setName($name)
{
$this->setAttribute('name', $name);
return $this;
}
public function getName()
{
return $this->getAttribute('name');
}
public function setLabel($label)
{
$this->setOption('label', $label);
return $this;
}
public function getLabel()
{
$label = $this->getOption('label');
if (null !== $label) {
return $label;
}
return $this->getName();
}
public function setMessages($messages)
{
$this->_messages = $messages;
return $this;
}
public function getMessages()
{
return $this->_messages;
}
} |
What do you think about the possibility to set options for form elements?
For example, I need to set the tooltips to form elements. Had to abandon the use of Phalcon\Forms\Element, because I have not figured out how to do it.
It would be nice to have a method to set custom options:
Template:
The text was updated successfully, but these errors were encountered: