Editable drop-down field possible?

(10 posts) (2 voices)

Tags:

No tags yet.

  1. duane, Member

    Hi.

    I know that the normal HTML 'select' form field only allows a value from the list to be selected, but not a new entry not on the list added. Yet I've seen on some sites this has been done (e.g. The list has NameA, NameB and NameC and an 'add' option to type in NameD).

    Mydbr has something like this for a search & select field, but I don't think it is possible to use as an editable field on an editable form to add a value - is that right?
    Or is there a way?

    Posted 1 year ago #
  2. myDBR Team, Key Master

    Hi,
    you can use 'select_find' in editable where it adds search functionality into the selectlist. It still is a selectlist though.

    Usually the selectlist contains ID's and visible values from another table. So not only the editable value would need to be edited, but possibility to add new values to another table. This brings the issue that in many cases, the table where the selectlist comes from, contains more columns than just the value (id for sure, possible other values as well) which would make things bit that just adding a new value.

    What is the use case where you would need this?

    --
    myDBR Team

    Posted 1 year ago #
  3. duane, Member

    I'll give it a try.

    The use case for this is I am working on a project to classify content for use with machine learning. Ideally there would be a finite list of possible values to choose from any any particular category/feature. However at the moment we have to create that list and it is highly probably that we miss lots of options as we go through the first round of manually classifying data.

    As I and others are domain experts in the area (NGOs and their activities), we will have a good idea of what the new value should be, but I want to make that simple by just adding it as this is a boring and repetitive task, so making it possible without having to open a new window, add it then refresh the editable page would be nice (meaning it allows us to classify each item faster and with less effort).

    Does that clarify the use case?

    Duane

    Posted 1 year ago #
  4. myDBR Team, Key Master

    Do do you both assign the new value to a row (id or the visible value?) and add the newly added value to a parameter table where the other values come from?

    --
    myDBR Team

    Posted 1 year ago #
  5. duane, Member

    For now I'm keeping it simple and would want to insert the new value, auto id can handle id creation but won't be used in the dropdown/storage for now (doesn't need to be that normalised yet!) and likely the category for which it is an sub category for (which could be hard coded done in the insert query if it can't be picked up dynamically).

    I'd only use this approach with a few fields as most fields have a small, finite list of values. But for categorising the topic of content, just under 'human rights' there could be hundreds of possible values (hence the search_find will be useful there too!)

    Posted 1 year ago #
  6. myDBR Team, Key Master

    You could add a 'New'-option into the parameter list and check in submit if the user has selected the 'New'-option. Based on that you can ask user a new value and do necessary updates in the editing procedure.

    Something like this should work:

    select 'dbr.javascript', "
    function check_if_new(settings, cell)
    {
    var newval, $select=$(this).find('select'); if ($select.val()=='New...') {
    newval = prompt('New value?');
    if (!newval) {
    return false;
    }
    $select.append($('<option></option>').attr('value',newval).text(newval));
    $select.val(newval);
    }
    return true;
    }
    "; select 'dbr.editable', '[value]', 'sp_DBR_edit_value', 'in_id=id', 'type=select',
    'select=select "New..." union select value from params'
    ,"options={'onsubmit':check_if_new}"; select id, value from mydata;

    --
    myDBR Team

    Posted 1 year ago #
  7. duane, Member

    Thanks! I'll give that a try.

    Posted 1 year ago #
  8. duane, Member

    Hi. I'm back working on this aspect of things and can't yet get it to work. here is what I have done (slight differences but almost the same).

    1) I'm currently trying to apply this to a radiobutton
    2) It is in pageview mode
    3) The field returns 'addnew' but the label is 'add new'

    So what I've done with the above (after many experiments) is:
    select 'dbr.javascript', " function check_if_new(settings, cell) { var newval, $select=$(this).find('radiobutton');

    if ($select.val()=='addnew') { newval = prompt('New value?'); if (!newval) { return false; } $select.append($('<option></option>').attr('value',newval).text(newval)); $select.val(newval); } return true; } ";

    the the other code to call it is:

    SELECT 'dbr.editable', 'Purpose', 'sp_DBR_ai_classify_update', 'inContentID=id', 'type=radiobutton', "select=sp_get_field_values('content_purpose', '')", "options={'autosubmit':1, 'onsubmit':check_if_new, 'display':'inline'}";

    Any thing I've missed/got wrong?

    Duane

    Posted 1 year ago #
  9. myDBR Team, Key Master

    Couple of changes:

    1. To find the selected radiobutton in jQuery, use $(this).find('input[type=radio]:checked')
    2. As you are using radionbuttons, no need for option-tags. In fact, you can just change the selected radiobutton's value to the new one
    3. The select query does not need the parentheses, just use: select=sp_get_field_values 'content_purpose', ''

    Other than that, you should be fine.

    select 'dbr.javascript', "
    function check_if_new(settings, cell)
    {
    var newval, $selected=$(this).find('radiobutton'); if ($selected.val()=='addnew') {
    newval = prompt('New value?');
    if (!newval) {
    return false;
    }
    $selected.val(newval);
    }
    return true;
    }
    "; SELECT 'dbr.editable', 'Purpose', 'sp_DBR_ai_classify_update', 'inContentID=id', 'type=radiobutton',
    "select=sp_get_field_values 'content_purpose', ''",
    "options={'autosubmit':1, 'onsubmit':check_if_new, 'display':'inline'}";

    --
    myDBR Team

    Posted 1 year ago #
  10. duane, Member

    Fantastic - that solve it. Thanks as usual for your amazing support.

    Posted 1 year ago #

Reply

You must log in to post.