Skip to content
Snippets Groups Projects
Commit 289cfe24 authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #4 from greezybacon/feature/textbox-selection-widget

forms: Add validator error to textbox widget for selection field
parents dd0da7a5 46b17ffd
No related branches found
No related tags found
No related merge requests found
...@@ -1324,10 +1324,14 @@ class SelectionField extends FormField { ...@@ -1324,10 +1324,14 @@ class SelectionField extends FormField {
if (!$this->errors()) { if (!$this->errors()) {
$config = $this->getConfiguration(); $config = $this->getConfiguration();
if ($config['widget'] == 'textbox') { if ($config['widget'] == 'textbox') {
if (!$entry if ($entry && (
|| !($k=key($entry)) !($k=key($entry))
|| !($i=$this->getList()->getItem((int) $k))) || !($i=$this->getList()->getItem((int) $k))
$this->_errors[] = __('Unknown or invalid input'); )) {
$config = $this->getConfiguration();
$this->_errors[] = $this->getLocal('validator-error', $config['validator-error'])
?: __('Unknown or invalid input');
}
} elseif ($config['typeahead'] } elseif ($config['typeahead']
&& ($entered = $this->getWidget()->getEnteredValue()) && ($entered = $this->getWidget()->getEnteredValue())
&& !in_array($entered, $entry)) && !in_array($entered, $entry))
...@@ -1362,6 +1366,17 @@ class SelectionField extends FormField { ...@@ -1362,6 +1366,17 @@ class SelectionField extends FormField {
), ),
'hint'=>__('Typeahead will work better for large lists') 'hint'=>__('Typeahead will work better for large lists')
)), )),
'validator-error' => new TextboxField(array(
'id'=>5, 'label'=>__('Validation Error'), 'default'=>'',
'configuration'=>array('size'=>40, 'length'=>80,
'translatable'=>$this->getTranslateTag('validator-error')
),
'visibility' => new VisibilityConstraint(
new Q(array('widget__eq'=>'textbox')),
VisibilityConstraint::HIDDEN
),
'hint'=>__('Message shown to user if the item entered is not in the list')
)),
'prompt' => new TextboxField(array( 'prompt' => new TextboxField(array(
'id'=>3, 'id'=>3,
'label'=>__('Prompt'), 'required'=>false, 'default'=>'', 'label'=>__('Prompt'), 'required'=>false, 'default'=>'',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment