Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82217

If checkbox in the editor field became selected, change the content of the editor field and store it

$
0
0

Hello everybody

I've been sitting on a more complex topic for days.

I have a lot of input fields with prices in an editor form (e.g. db.reg_price and db.red_price). You can enter this by hand. Underneath there is the possibility to activate a checkbox. If this has been activated, the array should be taken from another table with these prices (reg_price and red_price without db. ).

Up to this point, this also works very well. Even the data in the table contain the values (reg_price and red_price) after saving the form. BUT! These values are not updated in the database in the original variables (db_reg_price and db_red_price). Only when you go into the editor field again and save again, does it take the values into the database.

  1. Is there a possibility to update both variables with this new values from the second table?

I made some tests with ->on('preEdit', function and also with postEdit and so on in the staff.php. Also with editor.on( 'preSubmit', function in the Javascript. But I don't find the right solution.

  1. Is there a possibility to block the fields in editor form if the checkbox were activated?

I'll be at one's wit's end....

Thanks a lot.
Mac

Javascript:

var editor; 

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
fields: [
   {
                type: "select",
                label: "Select price package:",
                name: "event.db_price_select_form",
                placeholder: "Please select"
            }, {
                label: "Regular price:",
                name: "event.db_reg_price",
                fieldInfo: "Format: 16.00",
                    
                }, {
                label: "Reduced price:",
                name: "event.db_red_price",
                fieldInfo: "Format: 16.00",
            },
.....

var table = $('#example').DataTable( {

 columns: [
            
            { data: "event.db_price_select",
                render: function (data, type, row) {
                    if (row.event.db_price_select == 1) {
                        return 'Yes';
                    } else {
                        return 'No';
                    }
                }
            },
            { data: "event.name_price_pack" },

            { data: "event.db_reg_price",
            render: function (data, type, row) {
                    if (row.event.db_price_select == 1) {
                        row.event.db_reg_price = row.price.reg_price;
                        return row.price.reg_price;
                    } else {
                        return row.event.db_reg_price;
                    }
                }
            },
......

staff.php:

......
        Field::inst( 'event.db_price_select_form' )
            ->options( Options::inst()
                ->table( 'price' )
                ->value( 'id' )
                ->label( array ( 'name_price_pack', 'reg_price', 'red_price' ))
            )
            ->validator( Validate::dbValues() ),
            Field::inst( 'price.name_price_pack' ),
            Field::inst( 'price.reg_price' ),
            Field::inst( 'price.red_price' ),

        Field::inst( 'event.db_reg_price' ),
        Field::inst( 'event.db_red_price' ),

->leftJoin( 'price', 'price.id', '=', 'event.db_price_select_form' )

.....


Viewing all articles
Browse latest Browse all 82217

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>