Dynamic text (read-only)

Dynamic text (read-only)

nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
edited November 2012 in General
In the Editor input form, I want to have a read-only field (ideally, no input, but only text) which is displayed conditionally, based on an integer value (this integer is provided by the joined table).

E.g.

if (x=1) > display: Audience: doctors
if (x=2) > display: Adience: patients

1) How can I achieve this result?
(code below doesn't work, and readonly isn't intuitive)
,{
"label": "Audience:",
"labelInfo":,
"type": "readonly"
}

Replies

  • nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
    Tried with this:

    {
    "label": "Audience:",
    "name":"tblFAQCategories.IsPatientCat",
    "default":tblFAQCategories.IsPatientCat,
    "type": "readonly"
    }

    But never mind: it is probably not possible with this pluging (data-dependent showing based on which SELECT is chosen in the form)
  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin
    In order to just have plain text (not an input control with readonly set) you'd need to have a plug-in field type which just displays the value as plain text ( http://editor.datatables.net/tutorials/field_types ). To have it conditionally set a value you could use use the `onPreEdit` and `onPreCreate` methods. Something like:

    [code]
    editor.on( 'onPreEdit', function () {
    editor.val( 'tblFAQCategories.IsPatientCat', editor.val('getField?') === 1 ? 'Audience: doctors' : 'Audience: patients' );
    } );
    [/code]

    Allan
  • nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
    Thanks for the answer.

    How would I concatenate two values in the SELECT box?

    I.e.

    Current code:

    editor_faqQuestions.field('f_FAQCID').update( json.tblFAQCategories );

    json.tblFAQCategories is provided in a separate query:

    ->select( 'tblFAQCategories', 'FAQCID as value, FAQCName as label' )

    )

    However, there is a field "IsPatientCat" (value 0/1) for each category. Can I include this in the above query?

    My goal is to populate the SELECT box with

    FAQCName ({if (IsPatientCat == 0 ) ? Therapists : Patients })

    Any suggestions for me?

    #

    Also: where can I find documentation on the Field>update method?
  • nskwortsownskwortsow Posts: 120Questions: 0Answers: 0
    I think I figured it out: matter of redoing the query, similar to the self-join example. I'll be back if I need more help on this.

    $out['userList'] = array();
    while ( $row = $userList->fetch() ) {
    $out['userList'][] = array(
    "value" => $row['id'],
    "label" => $row['id'].' '.$row['first_name'].' '.$row['last_name']
    );
    }
  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin
    Exactly like that :-). Nice one.

    Allan
  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin
    > Also: where can I find documentation on the Field>update method?

    Hmmm - unfortunately that isn't actually correctly documented on the site. Thanks for picking that up - I will ensure that is rectified. Basically it is just a call for the select, checkbox and radio methods to update the source data.

    Allan
This discussion has been closed.