-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Select multiple changes name from users to users[][] #150
Comments
Is it changing from |
From |
Can you please give me your form structure so i can test? Thanks. |
It's little messy, but it worked in previous version (1.6.12). <?php namespace App\Forms;
use Carbon\Carbon;
use Kris\LaravelFormBuilder\Form;
class CalendarForm extends Form
{
public function buildForm()
{
$this->setOptions();
$this->add('title', 'text', [
'label' => 'Tytuł wydarzenia',
]);
$this->add('note', 'textarea', [
'label' => 'Opis',
'attr' => [
'rows' => 3
]
]);
$this->add('all_day', 'checkbox', [
'label' => 'Cały dzień',
'wrapper' => [
'class' => 'form-group'
],
]);
$this->add('start', 'datetime', [
'label' => 'Rozpoczęcie',
]);
$this->add('duration', 'number', [
'label' => 'Czas trwania w minutach',
]);
$this->add('users', 'select', [
'label' => 'Kto będzie na spotkaniu',
'choices' => $this->getUsers(),
'attr' => [
'class' => 'form-control select2',
'multiple' => 'multiple'
]
]);
$this->add('color', 'color', [
'label' => 'Kolor etykiety',
]);
$this->add('submit', 'submit', [
'label' => property_exists($this->getModel(), 'id') ? 'Edytuj wydarzenie' : 'Dodaj wydarzenie',
'attr' => [
'name' => 'calendar',
'value' => 1
]
]);
}
private function setOptions()
{
$this->setFormOption('method', 'POST');
if ($this->getFormOption('application')) {
$this->setFormOption('url', route('application.flow'));
} else {
if ($this->getModel()) {
$this->setFormOption('url', route('task.update'));
} else {
$this->setFormOption('url', route('task.store'));
}
}
if ($this->getModel()) {
$this->setModelProperties();
}
}
private function getUsers()
{
$selected = [\Sentinel::getUser()->id];
$users = [
\Sentinel::getUser()->id => 'Ja',
];
$app = $this->getFormOption('application');
if($app) {
$users[$app->candidate->id] = $app->candidate->full_name;
$selected[] = $app->candidate->id;
foreach(\App\Entities\User::whereWorker(1)->where('id', '!=', \Sentinel::getUser()->id)->get() as $worker) {
$users[$worker->id] = $worker->full_name;
}
} else {
foreach (\App\Entities\User::all() as $worker) {
$users[$worker->id] = $worker->full_name;
}
}
$this->setSelectedUsers($selected);
return $users;
}
private function setSelectedUsers($ids = [])
{
if (!$this->getModel()) {
$model = new \stdClass();
$model->users = $ids;
$this->setModel($model);
}
}
private function setModelProperties()
{
$model = $this->getModel();
$this->add('task_id', 'hidden', [
'value' => $model->id
]);
$model->users = $model->workers->lists('id')->toArray();
}
} |
@zalazdi |
Yeah, now it's work. But i got another error. I'm opening new issue. |
I'm getting hit by this as well. Any chance you can release a new version including the fix in #151? |
After upgrade to 1.6.20, field Select with multiple attr changes field name from users to users[][](double brackets).
I noticed that FormField@prepareOptions are executed two times.
The text was updated successfully, but these errors were encountered: