Split value in one editor field to populate many db fields

Split value in one editor field to populate many db fields

dynasoftdynasoft Posts: 439Questions: 68Answers: 3

Hi

I have 5 db fields that I merge into one editor field on the editor UI. How can I the read and split the content of this editor field to set my 5 db fields in turn? Many thanks.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @dynasoft ,

    Are you merging those fields as in this example? If not could you give more information, please.

    Cheers,

    Colin

  • dynasoftdynasoft Posts: 439Questions: 68Answers: 3
    edited May 2019

    Thanks. Yes I am using the same merging code in render.

    DataTable has:

                    columns: [
                        { data: 'id' },
                        { data: 'ContactType' },
                        { data: 'ContactIndex' },
                        { data: 'NotesDateTime' },
                        { data: 'NotesSubject' },
                        { data: null, 
                          render: function ( data, type, row ) {    //combine body fields                        
                            return data.NotesBody1 + data.NotesBody2 + data.NotesBody3 + data.NotesBody4 + data.NotesBody5;
                        } },
    

    HTML:


    <th>ID</th> <th>ContactType</th> <th>ContactID</th> <th>@lblo.lblDateTime</th> <th>@lblo.lblSubject</th> <th>@lblo.lblNote</th>

    Editor:


    fields: [ { label: '@(lblo.lblDateTime):', name: 'NotesDateTime', type: 'datetime', format: '@(dateFormat.ToUpper() + ' ' + timeFormat)', def: function () { return new Date(); } }, { label: '@(lblo.lblSubject)*:', name: 'NotesSubject' }, { label: '@(lblo.lblNote):', name: 'NotesBody', type: 'textarea', attr: { rows: "5" }

    Server side:

                    using (Database db = new Database(SetGetDbType2, SetGetDbConnection))
                    {
                        editor = new Editor(db, "ContactNotes").Model<ContactNotesDBModel>();
                        editor.Field(new Field("id")
                            .Set(false)
                        );
                        editor.Field(new Field("ContactType")
                            .Set(true)
                            .SetValue(tpe)
                        );
                        editor.Field(new Field("ContactIndex")
                            .Set(true)
                            .SetValue(id)
                        );
                        editor.Field(new Field("NotesDateTime")
                            
                        );
                        editor.Field(new Field("NotesSubject")
                            .Validator(Validation.NotEmpty(new ValidationOpts
                            {
                                Message = lblo.lblEnsureValueIdentified
                            }))
                        );
                        editor.Field(new Field("NotesBody1")
                            //.SetFormatter(Format.IfEmpty(null))
                            .SetFormatter((val, data) => CommonUtilities.ToString(val))
                        );
                        editor.Field(new Field("NotesBody2")
                            //.SetFormatter(Format.IfEmpty(null))
                            .SetFormatter((val, data) => CommonUtilities.ToString(val))
                        );
                        editor.Field(new Field("NotesBody3")
                            //.SetFormatter(Format.IfEmpty(null))
                            .SetFormatter((val, data) => CommonUtilities.ToString(val))
                        );
                        editor.Field(new Field("NotesBody4")
                            //.SetFormatter(Format.IfEmpty(null))
                            .SetFormatter((val, data) => CommonUtilities.ToString(val))
                        );
                        editor.Field(new Field("NotesBody5")
                            //.SetFormatter(Format.IfEmpty(null))
                            .SetFormatter((val, data) => CommonUtilities.ToString(val))
                        );
    
  • dynasoftdynasoft Posts: 439Questions: 68Answers: 3

    I'm looking to use the data in ediyor field NotesBody and save it in the 5 db fields NotesBody1, NotesBody2... by splitting the data in chunks. Our db is structured that string db fields are limited to 255 chars, hence need to merge data for UI and then split data back for the db. Thanks.

  • dynasoftdynasoft Posts: 439Questions: 68Answers: 3

    I should be able to find a solution if I can read the value stored in editor field NotesBody from the server. All I find that deals with this is the server events like:

    editor.PreEdit += (sender, e) => strTp = CommonUtilities.ToString(e.Values["NotesBody"]);

    How can I modify this so I can read the e.Values["NotesBody"] and store this into a variable? Thanks.

  • dynasoftdynasoft Posts: 439Questions: 68Answers: 3
    Answer ✓

    Hi, I was on the right track as using a mix of the preedit event and e.Values gets me the data formatted correctly

                    editor.PreEdit += (sender, e) => editor.Field("NotesBody1").SetValue(e.Values["NotesBody"]);
                    editor.PreEdit += (sender, e) => editor.Field("NotesBody2").SetValue(e.Values["NotesBody"]);
    
  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Ah, glad you got it working!

    C

This discussion has been closed.