Merge pull request #934 from Flynsarmy/removeFormField
Add support for removing form fields
This commit is contained in:
commit
77d0d25f64
|
|
@ -83,6 +83,26 @@ class FormTabs implements IteratorAggregate, ArrayAccess
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a field from all tabs by name.
|
||||
* @param string $name
|
||||
* @return True on success, False on failure
|
||||
*/
|
||||
public function removeField($name)
|
||||
{
|
||||
foreach ($this->fields as $tab => $fields) {
|
||||
foreach ($fields as $fieldName => $field) {
|
||||
if ($fieldName == $name) {
|
||||
unset($this->fields[$tab][$fieldName]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a field to the collection of tabs.
|
||||
* @param string $name
|
||||
|
|
|
|||
|
|
@ -459,6 +459,27 @@ class Form extends WidgetBase
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Programatically remove a field.
|
||||
* @return True on success, False on failure
|
||||
*/
|
||||
public function removeField($name)
|
||||
{
|
||||
if (!isset($this->fields[$name])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove from tabs
|
||||
$this->primaryTabs->removeField($name);
|
||||
$this->secondaryTabs->removeField($name);
|
||||
$this->outsideTabs->removeField($name);
|
||||
|
||||
// Remove from form
|
||||
unset($this->fields[$name]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Programatically add fields, used internally and for extensibility.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue