Radio, MultiCheckbox and Select with dynamically added values #2584

Closed
zfbot opened this Issue Sep 28, 2012 · 3 comments

Projects

None yet

3 participants

@zfbot

Jira Information

Original Issue: ZF2-558
Issue Type: Bug
Reporter: Chris Willis
Created: 09/14/12
Assignee: weierophinney
Components: Zend\Form

Description

The Radio, MultiCheckbox and Select elements insert an InArray validator to check the selected item(s) exist for validation, however the validator's haystack isn't updated when the values have been dynamically added after the validator has been attached.

This can be fixed by:

  /**
   * @param  array $options
   * @return Select
   */
  public function setValueOptions(array $options)
  {
      $this->valueOptions = $options;
+ 
+     // Update InArray validator haystack
+     if (!is_null($this->validator)) {
+         $validator = $this->validator->getValidator();
+         $validator->setHaystack($this->getValueOptionsValues());
+     }
+     
      return $this;
  }
  /**
   * @param  array $options
   * @return Select
   */
  public function setValueOptions(array $options)
  {
      $this->valueOptions = $options;
+ 
+     // Update InArray validator haystack
+     if (!is_null($this->validator)) {
+         $validator = $this->validator instanceof InArray ? $this->validator : $this->validator->getValidator();
+         $validator->setHaystack($this->getValueOptionsValues());
+     }
+     
      return $this;
  }
@zfbot

(Originally posted by: igormx on 09/20/12)

I have a pull request with Chris Wills solution #2393

@zfbot

This issue was ported from the ZF2 Jira Issue Tracker at
http://framework.zend.com/issues/browse/ZF2-558

Known GitHub users mentioned in the original message or comment:
@weierophinney, @igormx

@cgmartin

This one was fixed in #2393 and #2438, and can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment