本文整理汇总了PHP中Nette\Forms\Container::addSelect方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::addSelect方法的具体用法?PHP Container::addSelect怎么用?PHP Container::addSelect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Forms\Container
的用法示例。
在下文中一共展示了Container::addSelect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addToFormContainer
/**
* Get assambled form
* @param Nette\Forms\Container $container
* @return void
*/
public function addToFormContainer($container)
{
/** @var Nette\Application\UI\Form $form */
$form = $container->lookup('Nette\\Application\\UI\\Form');
$translator = $form->getTranslator();
$main_options = [];
/**
* First foreach for filling "main" select
*/
foreach ($this->group_actions as $id => $action) {
$main_options[$id] = $action->getTitle();
}
$container->addSelect('group_action', '', $main_options)->setPrompt('ublaboo_datagrid.choose');
/**
* Second for creating select for each "sub"-action
*/
foreach ($this->group_actions as $id => $action) {
$control = NULL;
if ($action instanceof GroupSelectAction) {
if ($action->hasOptions()) {
$control = $container->addSelect($id, '', $action->getOptions());
$control->setAttribute('id', static::ID_ATTRIBUTE_PREFIX . $id);
}
} else {
if ($action instanceof GroupTextAction) {
$control = $container->addText($id, '');
$control->setAttribute('id', static::ID_ATTRIBUTE_PREFIX . $id)->addConditionOn($container['group_action'], Form::EQUAL, $id)->setRequired($translator->translate('ublaboo_datagrid.choose_input_required'))->endCondition();
} else {
if ($action instanceof GroupTextareaAction) {
$control = $container->addTextarea($id, '');
$control->setAttribute('id', static::ID_ATTRIBUTE_PREFIX . $id)->addConditionOn($container['group_action'], Form::EQUAL, $id)->setRequired($translator->translate('ublaboo_datagrid.choose_input_required'));
}
}
}
if ($control) {
/**
* User may set a class to the form control
*/
if ($class = $action->getClass()) {
$control->setAttribute('class', $class);
}
/**
* User may set additional attribtues to the form control
*/
foreach ($action->getAttributes() as $name => $value) {
$control->setAttribute($name, $value);
}
}
}
foreach ($this->group_actions as $id => $action) {
$container['group_action']->addCondition(Form::EQUAL, $id)->toggle(static::ID_ATTRIBUTE_PREFIX . $id);
}
$container['group_action']->addCondition(Form::FILLED)->toggle(strtolower($this->datagrid->getName()) . 'group_action_submit');
$container->addSubmit('submit', 'ublaboo_datagrid.execute')->setAttribute('id', strtolower($this->datagrid->getName()) . 'group_action_submit');
if ($form instanceof Nette\ComponentModel\IComponent) {
$form->onSubmit[] = [$this, 'submitted'];
}
}
示例2: addToFormContainer
/**
* Adds select box to filter form
* @param Nette\Forms\Container $container
*/
public function addToFormContainer($container)
{
$form = $container->lookup('Nette\\Application\\UI\\Form');
$translator = $form->getTranslator();
$select = $container->addSelect($this->key, $translator->translate($this->name), $this->options);
if (!$this->translateOptions) {
$select->setTranslator(NULL);
}
}
示例3: addToFormContainer
/**
* Get assambled form
* @param Nette\Forms\Container $group_action_container
* @param Form $form
* @param Nette\Localization\ITranslator $translator
* @return void
*/
public function addToFormContainer($group_action_container, $form, $translator = NULL)
{
/**
* First foreach for filling "main" select
*/
foreach ($this->group_actions as $id => $action) {
$main_options[$id] = $action->getTitle();
}
$group_action_container->addSelect('group_action', '', $main_options)->setPrompt($translator ? $translator->translate('Choose') : 'Choose');
/**
* Second for creating select for each "sub"-action
*/
foreach ($this->group_actions as $id => $action) {
if ($action->hasOptions()) {
$group_action_container->addSelect($id, '', $action->getOptions())->setAttribute('id', static::ID_ATTRIBUTE_PREFIX . $id);
}
}
foreach ($this->group_actions as $id => $action) {
$group_action_container['group_action']->addCondition(Form::EQUAL, $id)->toggle(static::ID_ATTRIBUTE_PREFIX . $id);
}
$group_action_container['group_action']->addCondition(Form::FILLED)->toggle('group_action_submit');
$group_action_container->addSubmit('submit', $translator ? $translator->translate('Do') : 'Do')->setAttribute('id', 'group_action_submit');
$form->onSubmit[] = [$this, 'submitted'];
}
示例4: createInput
/**
* @param Container $form
* @return \Nette\Forms\IControl|NULL
* @throws Exception
*/
public function createInput(Container $form)
{
$name = $this->getName();
$input = NULL;
$items = [];
if ($options = (array) $this->getValue('options')) {
foreach ($options as $key => $option) {
$items[$key] = $option['option'];
}
}
switch ($this->type) {
case 'text':
$input = $form->addText($name);
break;
case 'textarea':
$input = $form->addTextArea($name);
break;
case 'radio':
$input = $form->addRadioList($name, NULL, $items);
break;
case 'checkbox':
$input = $form->addCheckboxList($name, NULL, $items);
break;
case 'select':
if ($this->getValue('multiple')) {
$input = $form->addMultiSelect($name)->setItems($items, FALSE);
}
if (!$this->getValue('multiple')) {
$input = $form->addSelect($name)->setItems($items, FALSE);
}
break;
default:
throw new \Exception();
}
if ($this->getValue('isRequired') && isset($input)) {
$input->setRequired(TRUE);
}
return $input;
}
示例5: createComponentGrid
/** Vytvoří komponentu gridu
*
*/
protected function createComponentGrid()
{
$grid = new MyDatagrid();
$grid->setTranslator($this->translator);
$grid->setShowCheckboxes(TRUE);
$grid->addColumn('login', 'Uživatelské jméno')->enableSort();
$grid->addColumn('roleName', 'Skupina')->enableSort();
$grid->addColumn('active', 'Aktivní')->enableSort();
$grid->addColumn('lastLogged', 'Poslední přihlášení')->enableSort();
$grid->addColumn('ip', 'IP adresa')->enableSort();
$grid->addCellsTemplate(APP_DIR . "/templates/" . $this->getName() . "/row-actions.latte");
$grid->setRowPrimaryKey('userID');
$model = $this->userRepository;
$user = $this->user;
$grid->setDatasourceCallback(function ($filter, $order, $paginator) use($model, $user) {
if ($user->isInRole("root")) {
$data = $model->read($paginator);
} else {
$data = $model->read($paginator)->where("login != ?", "root")->where("userID = ? OR user.aclRoleID != ?", array($user->getId(), $user->getIdentity()->data['aclRoleID']));
}
foreach ($filter as $k => $v) {
$k = str_replace("roleName", "role.name", $k);
$data->where($k . " LIKE ?", "%" . $v . "%");
}
if ($order) {
$order = str_replace("roleName", "role.name", implode(" ", $order));
$data->order($order);
}
// Role name hacking
foreach ($data as $entity) {
$entity->setRoleName($entity->getRole()->getName());
}
return $data;
});
$grid->setPagination(10, function ($filter) use($model) {
$data = $model->read();
foreach ($filter as $k => $v) {
$k = str_replace("roleName", "role.name", $k);
$data->where($k . " LIKE ?", "%" . $v . "%");
}
return $data->count('*');
});
$roleModel = $this->roleRepository;
$grid->setFilterFormFactory(function () use($roleModel) {
$form = new Container();
$form->addText("login", "Uživatelské jméno");
$form->addSelect("roleName", "Skupina", $roleModel->read()->fetchPairs("name", "name"))->setPrompt("Vše");
$form->addSelect("active", "Aktivní", array("0" => "Neaktivní", "1" => "Aktivní"))->setPrompt("Vše");
$form->addText("lastLogged", "Poslední přihlášení");
$form->addText("ip", "IP adresa");
// these buttons are not compulsory
$form->addSubmit('filter', 'Filtrovat')->getControlPrototype()->class = 'btn btn-primary';
$form->addSubmit('cancel', 'Storno')->getControlPrototype()->class = 'btn';
return $form;
});
return $grid;
}
示例6: addControl
/**
* @param Nette\Forms\Container $container
* @param string $key
* @param string $name
* @param array $options
* @return Nette\Forms\Controls\SelectBox
*/
protected function addControl(Nette\Forms\Container $container, $key, $name, $options)
{
$input = $container->addSelect($key, $name, $options);
return $this->addAttributes($input);
}