zendframework / zend-form

Form component from Zend Framework
BSD 3-Clause "New" or "Revised" License
69 stars 87 forks source link

Allow additions to view helper valid attributes #194

Closed Brindster closed 6 years ago

Brindster commented 6 years ago

Currently, the list of valid attributes on the form view helpers is fixed. This pull request adds the ability to add additional valid attributes to view helpers.

My use case is that certain javascript frameworks use non standard attributes (such as ng-, v-) when binding on form elements. It would simplify development if Zend/Form were able to specify these attributes on form inputs.

froschdesign commented 6 years ago

@Brindster

This pull request adds the ability to add additional valid attributes to view helpers.

Your commit includes something more:

/**
 * Attribute prefixes valid for all tags
 *
 * @var array
 */
protected $validTagAttributePrefixes = [
    'data-' => true,
    'aria-' => true,
    'x-'    => true,
];

https://github.com/Brindster/zend-form/blob/81f282411c9b202c2a483d310c2a81e14eb9bdd6/src/View/Helper/AbstractHelper.php#L164-L173

/**
 * Adds a prefix to the list of valid attribute prefixes
 *
 * @param string $prefix
 *
 * @return AbstractHelper
 */
public function addValidAttributePrefix($prefix)
{
    $this->validTagAttributePrefixes[$prefix] = true;
    return $this;
}

https://github.com/Brindster/zend-form/blob/81f282411c9b202c2a483d310c2a81e14eb9bdd6/src/View/Helper/AbstractHelper.php#L475-L486

Please don't mix different topics in one commit. That would help a lot!

froschdesign commented 6 years ago

For the moment I added the label "work in progress". I have to look for side effects.

froschdesign commented 6 years ago

Related to #50

Brindster commented 6 years ago

Apologies for the mixed initial commit, I'll try and be more careful in future. Validation and non-optimal test cases have been added.

weierophinney commented 6 years ago

Thanks, @Brindster!