Replace character in string on create/update

Replace character in string on create/update

peterbrownepeterbrowne Posts: 314Questions: 54Answers: 0

I want to replace semicolons and colons with their Hex Code equivalents on create and update in the edit functions. How do I do that?

Answers

  • peterbrownepeterbrowne Posts: 314Questions: 54Answers: 0
    edited April 2023

    I have tried:

    ```columns: [ {
    data: "program_outcome.program_outcome",
    render: function (data, type, row) {
    switch(data) {
    case ';':
    return ';';
    break;
    case ':':
    return ':';
    break;
    }
    },
    },``

    But I just get:

    DataTables warning: table id=program_outcome_table - Requested unknown parameter 'program_outcome.program_outcome' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    The rendering function there will change the data when displayed in the DataTable. It won't effect what is edited in Editor or the data saved to the database.

    In order to answer your question accurately, I think I'll need a little more information. For example, do you want the user to edit the data normally, but when saved it should use hex values in the database? If so, a set formatter would be the way to do it.

    Allan

  • peterbrownepeterbrowne Posts: 314Questions: 54Answers: 0
    edited April 2023

    Thanks Allan, That sounds like the way to do it, but I may need some more help to get it working. So where:

    entered value is a semi colon then substitute &#x3b;

    entered value is a colon then substitute :

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin
    Field::inst( 'status' )
        ->setFormatter( function ( $val ) {-
                    return str_replace( ':', '&#x3b;', $val );
        } )
    

    That's the semi-colon one. You can add another replace for the colon. That's today's homework ;)

    Out of interest - why?

    Allan

Sign In or Register to comment.