Add the ability to declare a select with options that have different values and text

This commit is contained in:
Kevin MacMartin 2019-07-17 00:21:28 -04:00
parent 6e2fb122d4
commit c03d2fc659
2 changed files with 13 additions and 4 deletions

View file

@ -202,13 +202,14 @@ Models with their `$dashboard_type` set to `edit` also use:
* `text`: Text input field for text data
* `mkd`: Markdown editor for text data containing markdown
* `date`: Date and time selection tool for date/time data
* `select`: Text input via option select with possible options in an `options` array
* `select`: Text input via option select
* `hidden`: Fields that will contain values to pass to the update function but won't appear on the page (this must be used for the sort column)
* `image`: Fields that contain image uploads
* `file`: Fields that contains file uploads
* `display`: Displayed information that can't be edited
* `user`: This should point to a foreign key that references the id on the users table; setting this will bind items to the user that created them
* `type-new`: This takes the same options as `type` and overrides it when creating new items (eg: to allow input on a field during creation but not after)
* `options` (required by `select`) Takes an array of options that are either strings or arrays containing the keys `title` (for what will display with the option) and `value` (for what will be recorded)
* `name`: (required by `file` and `image`) Used along with the record id to determine the filename
* `delete`: (optional for `file` and `image`) Enables a delete button for the upload when set to true
* `ext`: (required by `file`) Configures the file extension of the upload

View file

@ -43,10 +43,18 @@
@elseif($type == 'select')
<select class="text-input" name="{{ $column['name'] }}" id="{{ $column['name'] }}">
@foreach($column['options'] as $option)
@if($option === $value)
<option value="{{ $option }}" selected="selected">{{ $option }}</option>
@if(is_array($option))
@set('select_value', $option['value'])
@set('select_title', $option['title'])
@else
<option value="{{ $option }}">{{ $option }}</option>
@set('select_value', $option)
@set('select_title', $option)
@endif
@if($select_value === $value)
<option value="{{ $select_value }}" selected="selected">{{ $select_title }}</option>
@else
<option value="{{ $select_value }}">{{ $select_title }}</option>
@endif
@endforeach
</select>