Mask - phone number

Mask - phone number

ostmalostmal Posts: 102Questions: 33Answers: 0

Good afternoon!
I can't implement the "editor.mask" plugin»:
https://editor.datatables.net/plug-ins/field-type/editor.mask

You can see it here:
http://www.a0250268.xsph.ru/index.php/crm-kandidat

JS

(function($){

$(document).ready(function() {
    var editor = new $.fn.dataTable.Editor( {
        ajax: '/abc_crm/dt/my/crm_kandidat/crm_kandidat.php',
        table: '#crm_kandidat',
        fields: [
            {
                label: "tel:",
                name: "crm_kandidat.tel",
                type: "mask",
                mask: "+7(000)-000-00-00",
                placeholder: "+7(ххх)-ххх-хх-хх"
            }
        ],
        // --- Для редактирования внутри ячейки ---
        formOptions: {
            inline: {
                onBlur: 'submit'
            }
        }
    } );

    var table = $('#crm_kandidat').DataTable( {
        // dom: 'Bfrtip',   // Убираем кнопки
        // language: {
        //         url: '/abc_crm/dt/lang/russian.json' // Русификация
        // },
        language: {
            url: '../../lang/russian.json'
        },
        ajax: '/abc_crm/dt/my/crm_kandidat/crm_kandidat.php',

        columns: [
            {
                "data": "vybory_user_card.deputy"
            },
            {
                "data": "crm_kandidat.tel"
            }
        ],
        // --- Для редактирования внутри ячейки ---
        keys: {
                   columns: ':not(:first-child)',
                   keys: [ 9 ],
                   editor: editor,
                   editOnFocus: true
               },
       // ------------------------------------------
        select: true,
        lengthChange: false,
        buttons: [
            { extend: 'create', editor: editor },
            { extend: 'edit',   editor: editor },
            { extend: 'remove', editor: editor }
        ]
    } );
} );
}(jQuery));

This question has accepted answers - jump to:

Answers

  • Alexandr45Alexandr45 Posts: 30Questions: 1Answers: 3

    It works like this for me:

    editor.on('onOpen', function () {

    $('#DTE_Field_installers-Installers_phone').mask('+7(999)999-99-99');

    });

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

    On top of @Alexandr45 's suggestion, also see this example here: http://live.datatables.net/gefesida/1/edit

    Colin

  • ostmalostmal Posts: 102Questions: 33Answers: 0

    I appreciate your help, but an example http://live.datatables.net/gefesida/1/edit it doesn't work for me!
    Maybe I'm doing something wrong? I took the HTML and JS codes from this example – just one to one.
    I got it like this.
    I'm at a loss!

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394
    edited June 2021

    You are loading two versions of jQuery mask.

      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.min.js"></script>
    
     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.0/jquery.mask.js"></script>
    

    However, I see that the working example is doing the same thing. So this isn't any help.
    Are you certain that the rest of your code matches the example?

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

    It doesn't look like the table is being initialised in your code. You would need to do that to get the Editor code enabled to edit the table,

    Colin

  • ostmalostmal Posts: 102Questions: 33Answers: 0

    Thank you so much, I really forgot to connect Edit

  • ostmalostmal Posts: 102Questions: 33Answers: 0

    I'm sorry to bother you. In the example: http://live.datatables.net/gefesida/1/edit it shows how the mask is applied when entering a value in the field. And how to put a mask on the output of values in the table? In the example, the data is fixed with separators. I.e., for example, in the database I have the value "9090570341", and in the table "+7(909)-057-03-41" My example: http://www.a0250268.xsph.ru/

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

    I'm not clear what the question is, sorry. Are you asking for the formatting to also be applied to the database?

    Colin

  • ostmalostmal Posts: 102Questions: 33Answers: 0

    Sorry. In the database - not formatted:
    https://prnt.sc/16kjy57
    I would like it to be output in formatted form for the user.

  • ostmalostmal Posts: 102Questions: 33Answers: 0

    Understood: "render"

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

    That's right - you would use columns.render to get it displayed in the table.

    Colin

Sign In or Register to comment.