laravel-enso / select

Bulma styled single and multi-select component with a server-side option list builder
https://laravel-enso.com/examples/select
MIT License
26 stars 15 forks source link

Custom queryAttribute - missing options labels #40

Closed robbykrlos closed 5 years ago

robbykrlos commented 5 years ago

This is a bug.

Prerequisites

Description

Problem: Select options are missing names(labels). I'm trying to create a simple form where 1-n relations are set. I have a "Group" model, where a FK "permission_group_id" can be set. For this I tried using a select field with the options from the "PermissionGroup" controller

/app/Http/Controllers/Models/Permissiongroups/Options.php ` class Options extends Controller { use OptionsBuilder;

protected $model = PermissionGroup::class;

protected $queryAttributes = ['permission_group_name'];

public function query(Request $request)
{
    return PermissionGroup::query();
}

} /app/Forms/Templates/Models/group.json { "routePrefix": "models.groups", "sections": [ { "columns": 2, "fields": [ { "label": "Permission Group Id", "name": "permission_group_id", "value": null, "meta": { "type": "select", "multiple": false, "options": [], "source": "models.permissiongroups.options" } }, { "label": "Group Name", "name": "group_name", "value": null, "meta": { "custom": false, "type": "input", "content": "text", "disabled": false } } ] } ] } `

/app/Tables/Builders/Models/GroupTable.php ` class GroupTable extends Table { protected $templatePath = DIR.'/../../Templates/Models/groups.json';

public function query()
{
    return Group::selectRaw('
        groups.id as "dtRowId",
        groups.permission_group_id as "dtRowPermissionGroupId",
        groups.group_name as "dtRowGroupName"
    ');
}

} `

I think the problem is the deviation from the default "name" queryAttribute which is expected, and in my situation the "name" which should be used as select option label is called "permission_group_name"

Ajax call is returning a valid JSON ; image

Steps to Reproduce

Create a Select field which uses the options of a different model which has no "name" column.

Expected behavior

To see the options generated in the options

Actual behavior

Options are generated but without a name image

aocneanu commented 5 years ago

docs

label - string, optional, default name - the attribute that is to be used as label from the result/options list

the front end component needs this attribute. If you're using enso-form / vue-form you should add "label": "permission_group_name" to the field's meta object

robbykrlos commented 5 years ago

docs

label - string, optional, default name - the attribute that is to be used as label from the result/options list

the front end component needs this attribute. If you're using enso-form / vue-form you should add "label": "permission_group_name" to the field's meta object

Nice! Thank you. I'm still getting familiar with enso, had thought that the select documentation should have contained this detail, although makes perfect sense to be a front-end thing... duuh..

Now I know! Have a good weekend.

aocneanu commented 5 years ago

The link is from the select documentation, but the FE part :)

robbykrlos commented 5 years ago

The link is from the select documentation, but the FE part :)

<synapses firing>