Voyager relationship default value options

stephen

Sep 1st, 2017 06:08 PM

Hello Team Voyager,

First of all, thanks for all your work on Voyager - it's beautifully designed and although I've only recently started using it, it's a real pleasure to work with :)

I've been checking out the new relationship functionality in the dev branch and I was wondering if you plan to allow extra field options to be set via the BREAD interface?

One thing I'd like is to be able to have a default NULL / empty value selected in the dropdown. Currently the first record is pre-selected so it's not possible to have a NULL value or to force the user to make a conscious selection for the field.

I'm not sure of the best way of implementing this but maybe via some extra JSON options like described here.

Any thoughts?

Thanks!

Stephen

mark

Sep 2nd, 2017 08:39 AM

It is already possible to have a default null or empty value for the dropdown.

If I remember right it can be done like this:

{
    "null": "-- None --"
    "default" : "-- None --"
}

You can also add extra options to the dropdown like this:

{
    "options" : {
        "value": "Some Name"
    }
}
stephen

Sep 2nd, 2017 09:55 AM

Thanks Mark!

I think I might not have phrased my question clearly enough but I what I was really asking was about the new relationship functionality. When editing a relationship field, there is no way I can see to add these JSON settings... Do you have a plan to allow JSON settings on these fields?

mark

Sep 2nd, 2017 10:47 AM

Ahh, makes sense. Well I think it would be ideal to add this again, will take a talk with @Devdojo about this and keep you posted.

devdojo

Sep 2nd, 2017 08:40 PM

Hey @Stephen,

Thanks for the question :) I would love to implement this for version 1.0. How might you anticipate this would function in the new relationship section. I could always add 2 more fields in the selection details like so:

Voyager relationship modal

These rows will typically only be present in a belongsTo relationship, since this is the only relationship that would justify a single select dropdown.

Let me know if you think this would be a good solution.

@mark let me know your thoughts as well :)

Thanks!

stephen

Sep 3rd, 2017 07:34 AM

Hi @DevDojo,

Thanks for your reply! I've been thinking about this and what other use cases I might have...

I like the simplicity of what you've suggested but it might be a bit limited in terms of functionality. For example, on a relationship field like this, how could I set it to be required? Should it be done by setting the field to Not Null in the database table settings? Or should it be via a validation rule in the JSON details? Possibly both? I must admit, I find this part a little bit confusing in Voyager.

As I mentioned in my original post, when I have a dropdown field, I often want to be able to set an empty first option like "-- None --" or "-- Please Select --" to force the person filling out the form to make a conscious decision about the value. The way that it currently automatically pre-selects the first option from the relationship data is not ideal. It also prevents allowing a NULL value to be saved for this field, which is sometimes needed.

In your interface example above, even if I set a NULL value and a default value, I wouldn't be able to control the option label for that default value (eg. "-- None --"). I guess you could add another field but maybe it's better left to JSON since it isn't necessarily something everyone needs to do.

There might also be some other advanced settings needed for the relationship field like setting a validation message, the page_slug or a description. I imagine there could be some other options in the future so maybe the JSON details field is still needed for the relationships in order to cover all the possibilities.

I hope this all makes sense and is useful feedback - if anything is unclear, please let me know.

On a side note, regarding the UI, I really like the overall design and it's great to see how it is evolving. Recently I was trying another similar app, Directus. If you haven't seen it before, it has a very clean UI and might be worth a look to see how they've tackled the UI for managing tables and fields...

Cheers,

Stephen