inline(): clear field when edit is triggered

inline(): clear field when edit is triggered

jangojango Posts: 5Questions: 3Answers: 0

Hi,

I have the following use case:

  1. I have an editable field with some contents (category name for an item).
  2. When I click on it, I want the contents to clear out so I can start typing the category name right away (I am using an autocomplete plugin and it seems like a waste of time for the user to have to clear the field out).
  3. When the user hits enter, I want to submit the data in the field.

I know how to do #3, but I am not sure if it's possible to do #2. Any pointers?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Using the open event you might do something like:

    editor.on( 'open', function ( e, mode, action ) {
      if ( mode === 'inline' ) {
        var fieldName = editor.displayed()[0];
    
        editor.field( fieldName ).val( '' );
      }
    } );
    

    Allan

  • jangojango Posts: 5Questions: 3Answers: 0

    Ended up highlighting the text instead by using this:

      editor.on( 'open', function ( e, mode, action ) {
        if ( mode === 'inline' ) {      
          var fieldInstance = editor.field( editor.displayed()[0] );
          fieldInstance.input().select();
        }
      });   
    

    Thank you for the quick response and a great tool you are building :-)

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Very nice - thanks for posting back with your solution and for your kind words.

    Allan

This discussion has been closed.