Custom Field being not accessed

Custom Field being not accessed

shatrughanshatrughan Posts: 85Questions: 15Answers: 0
edited July 2020 in Editor

Hi,
I have a custom field named RO_Category with three number of buttons just alike todo list where only one button can be enabled at a time. Based upon the selection of these buttons, I want to have updated another field(not custom one) with select type.
Here is how I defined the custom field **RO_Category **

_fieldTypes.RO_Category = {
create: function ( conf ) {
  var that = this;

  conf._enabled = true;

  // Create the elements to use for the input
  conf._input = $(
      '<div id="'+Editor.safeId( conf.id )+'">'+
          '<button type="button" style="margin-right:2px;" id="btn1" class="inputButton" value="TPDS" data-toggle="tooltip"  data-placement="top" title="Targetted Public Distribution System">TPDS</button>'+
          '<button type="button" class="inputButton" id="btn2" value="OWS"  data-toggle="tooltip"   data-placement="top" title="Other Welfare Schemes">OWS</button>'+
           '<button type="button" class="inputButton" id="btn3" value="OMSS" data-toggle="tooltip"  data-placement="top" title="Open Market Sale Scheme">OMSS</button>'+
          
      '</div>');

  
  $('button.inputButton', conf._input).click( function () {
      if ( conf._enabled ) {
          that.set( conf.name, $(this).attr('value') );
          }

      return false;
  } );

  return conf._input;
},

get: function ( conf ) {
  return $('button.selected', conf._input).attr('value');
},

set: function ( conf, val ) {
  $('button.selected', conf._input).removeClass( 'selected' );
  $('button.inputButton[value='+val+']', conf._input).addClass('selected');
},

enable: function ( conf ) {
  conf._enabled = true;
  $(conf._input).removeClass( 'disabled' );
},

disable: function ( conf ) {
  conf._enabled = false;
  $(conf._input).addClass( 'disabled' );
}
};

In my index file, I have included these fields as below

{
          label: "RO_Category:",
          name: "RO_Category",
           type: "RO_Category",
          options: [ "TPDS", "OWS","OMSS" ],
          def : "TPDS",
        },
        {
          label: "RO_Sub_Category:",
          name: "RO_Sub_Category",
          type: "select",
        },

In order to have changed the select options of 2nd field based on selection of my custom field, i used following code

editor.field( 'RO_Category' ).input().on( 'change', function ()
                {
                  var scheme=editor.field( 'RO_Category' ).get();
                  if(scheme=='OWS')
                  {
                    editor.field('RO_Sub_Category').update(["MDM-Primary", "MDM-Upper Primary", "SAG","Defence","WIS"]);   
                  }
                  
                });

But, clicking on my custom buttons do nothing.
Please help me resolve this issue.

Regards
Shatrughan Sangwan

Answers

  • shatrughanshatrughan Posts: 85Questions: 15Answers: 0
    edited July 2020

  • shatrughanshatrughan Posts: 85Questions: 15Answers: 0
    edited July 2020

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    edited July 2020

    This sounds like dependent() would do the trick here - it allows you to trigger an action based on the value of a field. Can you take a look and see if that helps, please,

    Colin

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    Btw, your other two messages are blank, was that intended?

  • shatrughanshatrughan Posts: 85Questions: 15Answers: 0

    Also tried dependent(), but to no avail

    editor.dependent( 'RO_Category', function ( val, data, callback ) {
        return val === 'OWS' ?
            { hide: 'RO_Sub_Category' } :
            { show: 'RO_Sub_Category' };
    } );
    

    Clicking on the cutsom field button does not toggle the other field.

    How can i access the value of custom field (button) for conditional access ?

  • shatrughanshatrughan Posts: 85Questions: 15Answers: 0

    The two blank messages were not intended for the issue in question and hence updated to be blank as i couldn't find any option to delete the post. Thanks

  • shatrughanshatrughan Posts: 85Questions: 15Answers: 0

    Found a similar thread as depicted below

    But, couldn't figure out how to return node.
    Please help..

  • shatrughanshatrughan Posts: 85Questions: 15Answers: 0

    Got working..it needs to be defind in the custom field code itself - as follows

    $('button.inputButton', conf._input).click( function () {
          if ( conf._enabled ) {
              that.set( conf.name, $(this).attr('value') );
              if($(this).attr('value')=='OWS')
              {
              editor.field('RO_Sub_Category').update(["MDM-Primary", "MDM-Upper Primary", "SAG","Defence","WIS"]);
              }
              else if($(this).attr('value')=='TPDS')
              {
              editor.field('RO_Sub_Category').update(["AAY", "PHH", "PMGKAY-AAY","PMGKAY-PHH"]);
              }
    
    }
          return false;
      } );
    

    Thanks

This discussion has been closed.