How to modify this code

How to modify this code

lancwplancwp Posts: 90Questions: 20Answers: 1

When I enter form (not required for modification), when I enter pir1 or pairs values, the SUMPIR1 value is automatically equal to pir1 value multiplied by pairs value,How to modify this code, thanks

~~
{
label: "订单数量:",
name: "pairs"
},

         {
            label: "客户单价:",
            name: "pir1"
        },

         {
            label: "工厂价格:",
            name: "pir2"
        },  

         {
            label: "客户总款:",
            name: "sumpir1"

        },

~~

This question has an accepted answers - jump to answer

Answers

  • lancwplancwp Posts: 90Questions: 20Answers: 1
    edited November 2022

    SORRY,I update the correct CODE,When adding, I can get the required value through the interface,

    ->on( 'preCreate', function ( $editor, &$values ) {
    $editor
    ->field('sumpir1')
    ->setValue($values['pairs']*$values['pir1']);


    } )

    Because I want to be able to modify the calculation result when I add a new record, but not in this way, I want to automatically generate a value in the form when I enter the first two fields. If I want to modify the calculation result value, I can also modify it before I submit it

        $(document).ready(function() {
        // Create date inputs
    
    
            editor = new $.fn.dataTable.Editor( {
                ajax: "controllers/staff.php",
                table: "#example",
    
                fields: [ {
                        label: "订单号:",
                        name: "ydh"
                    },
    
    
         {
                        label: "订单数量:",
                        name: "pairs"
                    },
    
                     {
                        label: "客户单价:",
                        name: "pir1"
                    },
    
                     {
                        label: "工厂价格:",
                        name: "pir2"
                    },  
    
                     {
                        label: "客户总款:",
                        name: "sumpir1"
    
                    },      
    
        ],
    

    .........

  • lancwplancwp Posts: 90Questions: 20Answers: 1

    @colin Help me ,thanks

  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin
    Answer ✓

    It sounds like you want to bind an input event listener to the pir1 input element and take some action that will update the other fields - e.g.:

    editor.field('pir1').input().on('input', function () {\
      var pir1 = editor.field('pir1').val();
    
      editor.field('pir2').val( pir1 * 2 );
    });
    

    I don't think I've entirely understood the logic you want to apply in the function, but hopefully that will point you in the right direction.

    Allan

  • lancwplancwp Posts: 90Questions: 20Answers: 1

    Thank. That's all right

Sign In or Register to comment.