Editor Inline, input sent empty even he has value in first on edit

Editor Inline, input sent empty even he has value in first on edit

eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

Editor Inline, input sent empty even he has value before edit
this wired because i have the same table but with diffrent parmas in other view that working fine with editor inline
in this view when i want to edit, Air_Fare_T.AirFare_Code_T always sent empty on inline edit

i have this serverSide code:

 [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        public ActionResult GetDataAirFareTrip(int id)
        {
            var settings = Properties.Settings.Default;
            var formData = HttpContext.ApplicationInstance.Context.Request;

            using (var db = new DataTables.Database(settings.DbType, settings.DbConnection))
            {
                var editor = new DataTables.Editor(db, "Air_Fare_T", "Air_Fare_T_Id");
                editor.Where(q =>
                    q.Where("Air_Fare_T.AirFare_Costing_T_Id", "(SELECT AirFare_Costing_T_Id FROM Air_Fare_T WHERE AirFare_Costing_T_Id= " + id + ")", "IN", false)
                );
                editor.Model<ViewModel.AirFareTripEditorVM>("Air_Fare_T")
                   .Field(new Field("Air_Fare_T.Air_Fare_T_Id")
                    .Validator(Validation.Numeric())
                    .Set(false)
                )
                 .Field(new Field("Air_Fare_T.AirFare_Costing_T_Id")
                    .Validator(Validation.Numeric())
                )
                .Field(new Field("Air_Fare_T.AirFare_Code_T").Xss(true)
                .Validator(Validation.Numeric())
                .SetFormatter(Format.IfEmpty(null))
                )
                .Field(new Field("Air_Fare_T.Air_Fare_T_Type").Xss(true)
                .Validator(Validation.Numeric())
                .Options(new Options()
                        .Table("AirFare_Trip_Type")
                        .Value("AirFare_Trip_Type_Id")
                        .Order("AirFare_Trip_Type.AirFare_Trip_Type_Id")
                        .Label("AirFare_Trip_Type_Name")
                )
                .SetFormatter(Format.IfEmpty(null))
                )
                .Field(new Field("Air_Fare_T.Air_Fare_T_Currency").Xss(true)
                .Validator(Validation.Numeric())
                .Options(new Options()
                        .Table("CurrencyCosting")
                        .Value("Currency_Id")
                        .Order("CurrencyCosting.Currency_Id")
                        .Label("Currency_Name")
                        )
                .SetFormatter(Format.IfEmpty(null)))
                .Field(new Field("Air_Fare_T.Air_Fare_T_Price").Xss(true)
                .Validator(Validation.Numeric())
                .SetFormatter(Format.IfEmpty(null)))
                .Field(new Field("Air_Fare_T.Air_Fare_T_PAX").Xss(true)
                .Validator(Validation.Numeric())
                .SetFormatter(Format.IfEmpty(null)))
                .Field(new Field("Air_Fare_T.Air_Fare_T_Total").Xss(true)
                .Validator(Validation.Numeric())
                .SetFormatter(Format.IfEmpty(null)));
                editor.Model<ViewModel.CostingAirlineEditorVM>("Costing_Airlines")
                .LeftJoin("Costing_Airlines", "Costing_Airlines.Airline_Id", "=", "Air_Fare_T.AirFare_Code_T");
                editor.Model<ViewModel.AirFareTripTypeEditorVM>("AirFare_Trip_Type")
                .LeftJoin("AirFare_Trip_Type", "AirFare_Trip_Type.AirFare_Trip_Type_Id", "=", "Air_Fare_T.Air_Fare_T_Type");
                editor.Model<ViewModel.CurrencyCostingEditorVM>("CurrencyCosting")
                .LeftJoin("CurrencyCosting", "CurrencyCosting.Currency_Id", "=", "Air_Fare_T.Air_Fare_T_Currency");

                // Post functions
                editor.PreCreate += (sender, e) =>
                {
                    var totalVal = getTotalValTrip(e.Values, id);
                    editor.Field("Air_Fare_T.Air_Fare_T_Total").SetValue(totalVal[1]);
                    editor.Field("Air_Fare_T.Air_Fare_T_Price").SetValue(totalVal[0]);


                };
                editor.PreEdit += (sender, e) =>
                {
                    var totalVal = getTotalValTrip(e.Values, id);
                    editor.Field("Air_Fare_T.Air_Fare_T_Total").SetValue(totalVal[1]);
                    editor.Field("Air_Fare_T.Air_Fare_T_Price").SetValue(totalVal[0]);


                };
                editor.Process(formData.Unvalidated.Form);
                DtResponse data = editor.Data();
                return Json(data, JsonRequestBehavior.AllowGet);
            }
        }

This question has accepted answers - jump to:

Answers

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    this is the view code:

    <script>
    
        var editor = new $.fn.dataTable.Editor({
            ajax: '@Url.Action("GetDataAirFareTrip", "AirFare")?id='+@ViewBag.CostingId_AirFare+'',
            table: "#air_fare_table",
            fields: [
                {
                    name: "Air_Fare_T.AirFare_Costing_T_Id",
                    type: "hidden",
                    default: '@ViewBag.CostingId_AirFare',
    
    
                },
                {
                    name: "Air_Fare_T.AirFare_Code_T",
                    label: "קוד חברת תעופה:",
                    type: "select2",
                    initialValue: true,
                    opts: {
                        "language": "he",
                        "dir": "rtl",
                        "allowClear": true,
                        "theme": "bootstrap",
                        "minimumInputLength": 1,
                        "placeholder": {
                            "id": "",
                            "text": "בחרו קוד חברת תעופה"
                        },
                        ajax: {
                            url: '@Url.Action("getAirLineCodes", "SystemConstants")',
                            dataType: 'json',
                            data: function (params) {
                                return {
                                    Prefix: params.term,
                                };
                            },
                            processResults: function (data) {
                                return {
                                    results: $.map(data, function (item) {
                                        return {
                                            text: item.Name,
                                            id: item.Id
                                        }
                                    })
                                };
                                cache: true
                            },
                        }
                    }
                },
                {
                    name: "Air_Fare_T.Air_Fare_T_Type",
                    label: "סוג ערך:",
                    type: "select2",
                    "opts": {
                        "language": "he",
                        "dir": "rtl",
                        "allowClear": true,
                        "theme": "bootstrap",
                        "placeholder": {
                            "id": "",
                            "text": "בחרו סוג ערך"
                        },
                    },
                },
                {
                    name: "Air_Fare_T.Air_Fare_T_Currency",
                    label: "מטבע:",
                    type: "select2",
                    "opts": {
                        "language": "he",
                        "dir": "rtl",
                        "allowClear": true,
                        "theme": "bootstrap",
                        "placeholder": {
                            "id": "",
                            "text": "בחרו סוג מטבע"
                        },
                    }
    
                },
                {
                    name: "Air_Fare_T.Air_Fare_T_Price",
                    label: "עלות:",
                    type: "text",
                },
                {
                    name: "Air_Fare_T.Air_Fare_T_PAX",
                    label: "כמות אנשים:",
                    type: "text",
                },
                {
                    name: "Air_Fare_T.Air_Fare_T_Total",
                    type: "hidden",
                },
            ],
            i18n: DTE_i18n
        });
    
        var airFareTable = $('#air_fare_table').DataTable({
            dom: "Bt",
            "ajax": {
                "url": '@Url.Action("GetDataAirFareTrip", "AirFare")?id='+@ViewBag.CostingId_AirFare+'',
            },
            "language": {
                "url": "@HttpContext.Current.Application["VirDir"]/media/language/de_HEB.json"
            },
            "footerCallback": function (row, data, start, end, display) {
                var api = this.api(), data;
                for (var i = 1; i <= api.columns().count() - 1; i++) {
                    // Remove the formatting to get integer data for summation
                    var intVal = function (i) {
                        return typeof i === 'string' ?
                            i.replace(/[\$,]/g, '') * 1 :
                            typeof i === 'number' ?
                                i : 0;
                    };
    
                    // Total over all pages
                    total = api
                        .column(5)
                        .data()
                        .reduce(function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0);
    
                    ///person for trip
                    person = api
                        .column(4)
                        .data()
                        .reduce(function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0);
    
                    // Total over this page
                    pageTotal = api
                        .column(5, { page: 'current' })
                        .data()
                        .reduce(function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0);
    
                    // Update footer
                    $(api.column(5).footer()).html(
                        '$' + pageTotal
                    );
    
                    $('tr:eq(1) th:eq(' + i + ')', api.table().footer()).html(pageTotal / person);
                }
            },
            keys: {
                columns: ':not(:first-child)',
                editor: editor
            },
            select: true,
            columns: [
                { data: "Costing_Airlines.Airline_Code" },
                { data: "AirFare_Trip_Type.AirFare_Trip_Type_Name" },
                { data: "CurrencyCosting.Currency_Name"},
                { data: "Air_Fare_T.Air_Fare_T_Price" },
                { data: "Air_Fare_T.Air_Fare_T_PAX" },
                { data: "Air_Fare_T.Air_Fare_T_Total"},
    
    
            ],
            buttons: {
                buttons: [
                    {
                        extend: "create",
                        text: "new",
                        editor: editor,
                        className: "datatableB"
                    },
                    {
                        extend: "remove",
                        text: "delete",
                        editor: editor,
                        className: "datatableB"
                    }
    
                ],
                dom: {
                    button: {
                        tag: "button",
                        className: "btn"
                    },
                }
            }
        });
    
        $('#air_fare_table').on('click', 'tbody td:not(:first-child)', function (e) {
            editor.inline(this, {
                submit: 'allIfChanged'
            });
        });
    
    
    
    </script>
    
  • allanallan Posts: 61,439Questions: 1Answers: 10,052 Site admin

    Hi,

    Don't combine:

            keys: {
                columns: ':not(:first-child)',
                editor: editor
            },
    

    with:

        $('#air_fare_table').on('click', 'tbody td:not(:first-child)', function (e) {
            editor.inline(this, {
                submit: 'allIfChanged'
            });
        });
    

    Drop the second block - let KeyTable handle the inline editing itself. If you want allIfChanged add:

    formOptions: {
      inline: {
        submit: 'allIfChanged'
      }
    }
    

    to your Editor initialisation object.

    Regards,
    Allan

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0
    edited February 2020

    hey Allan, thanks for the replay
    i change as you recommend, but still its not working

  • allanallan Posts: 61,439Questions: 1Answers: 10,052 Site admin

    If you could give me a link to the page I'll debug it directly.

    Thanks,
    Allan

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    hey Allen, i think i figure out what happens , if i use allIfChanged in submit this is delete the selected2 ajax remote value, if i cancel this it work.

    inline: {
                   submit: 'allIfChanged',
     }
    

    what to do? i must get 3 field when one field is changed ?
    to make some field-total field calculation

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Please link to the page as Allan suggested, then we can take a look.

    Colin

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0
    edited April 2020

    on the airFare table, you can show if you will update one filed inline the airline company will be remove!
    please check it asap, thank
    i send link in p.m to allan thank

  • allanallan Posts: 61,439Questions: 1Answers: 10,052 Site admin

    Thanks for the link.

    i must get 3 field when one field is changed ?

    Yes - that is correct. Editor requires you to return the full data for the row in the same format that was used to load the row originally (which allows for server computed fields).

    Regarding the link - now that I've made an edit, how do I reassign a valid code for the air fare? It disappeared as you said, and I expected it to appear again on reload, but that isn't the case. So I'm not sure how to add it back in?

    Thanks,
    Allan

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    hey allan, you need to delete and add new one

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    i add 3 new row, you can play witj

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    i must say that when you change something in this row, it make calculation and i check always the air fare id come empty without value, so even if you refresh the page it will stay empty

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    hey Allan i have more question, how i can make editor options where to check if id is in list<int>, and that where will happen only on specific condition?

  • allanallan Posts: 61,439Questions: 1Answers: 10,052 Site admin
    Answer ✓

    Thanks for adding those rows. The problem relates to the value not being present in the Select2 field for the AirFare_Code.

    When you trigger editing on a cell, an Ajax request is sent to the server:

    http://pegasus-mvc2.bizpower.co.il/SystemConstants/getAirLineCodes?initialValue=true&value=3463

    That happens for Select2 fields so you can respond with the value and label option that should be shown in the field - e.g. [{label: "ISS", value: 3563}]. However, currently that script is just responding with []. Thus the Select2 field doesn't have a value and when the form is submitted it has an empty value sent for that field.

    You need to change getAirLineCodes to handle that initialValue request. Or if you don't want that field to be editable, remove it from the Editor fields.

    how i can make editor options where to check if id is in list<int>, and that where will happen only on specific condition?

    Do you mean as a validator? You would need a custom validator.

    Allan

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    "You need to change getAirLineCodes to handle that initialValue request. Or if you don't want that field to be editable, remove it from the Editor fields."

    allan if i remove this form editor field, i cannot create new row with this field
    no option just on edit not include this field?

  • allanallan Posts: 61,439Questions: 1Answers: 10,052 Site admin
    Answer ✓

    Ah okay - the easiest way to handle this then is going to be to add:

    .Set(Field.SetType.Create)
    

    for the Field in your C# code.

    That will result in the value being written to the database only on create, and ignored on edit.

    Alternatively, you could use initCreate and submitComplete to add and remove the field from the field list, but I think the Set() method is more secure (and easier).

    Allan

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    hey allan,
    .Set(Field.SetType.Create)
    worked wall, but if i want the to have validation on input in create mode it will work, but if i will try to edit inline, i will always get the required message for this field
    how i can make this work?

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    i also changed the code in getAirLineCodes to handle with initialValue request
    its worked and return the right option but still the field submit without value form inline edit

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    even if i try to edit regular not with inline, the select list empty

  • allanallan Posts: 61,439Questions: 1Answers: 10,052 Site admin

    Sounds like you might have some validation on the field which is marking it as required, even on edit?

    I'd suggest using your PreCreate event handler to add the validation for this field. That way it will validate on create only, not edit.

    Allan

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0
    edited June 2020

    hey allan i resolve this problem, its sound stupid, but initialValue need to return list with text and id in small latter, if initalValue value is empty you need to return list of Name and Id.

  • eyal_hbeyal_hb Posts: 98Questions: 31Answers: 0

    i have another question about editor date-time field, i want that if i will chose start date value the end date windows(not value) will open in the same month of the start date,
    i know i need to used dependent but i cant think about way to get and changed the initialize windows date of end date field

This discussion has been closed.