Link to home
Start Free TrialLog in
Avatar of Ralph
RalphFlag for United States of America

asked on

Linefeeds SOMETIMES returned from texarea - needed for comparison for differences Update

I'm taking as-loaded values from a form and backing them up into other inputs, using a textarea for the backup of the textarea to preserve linefeeds (supposedly).

When I first put the value containing "\n" into the form's textarea it breaks where it should, whether I put the value there via PHP or JS.

When I grab the value to put into a backup field the "\n"s are still there per console.log(value.indexOf("\n")) check in the last line below (now removed).
if ( formSpecs[f]['type'] !== '<textarea>' )
      { $('#invisible').append('<input type="text" name="orig_'+name+'" ID="orig_'+name+'" class="backup" value="'+value+'" />'+"\n") ; }
      else
      { $('#invisible').append('<input type="textarea" name="orig_'+name+'" ID="orig_'+name+'" class="backup" value="'+value+'" />'+"\n") ; }  // Want to preserve line feeds

Open in new window



Later when I grab the current value from the form for a second time it too has the linefeeds, but the backup version does not have them.

Sure I could remove them and do my compare to check for update need, but I need the linefeeds in the data.

Why would they be returned from the one input but not the 2nd?
Where I retrieve the original (value) and backed up value (orig_value):
$('form input, form select, form textarea, form checkbox')
   .each(
    function(index)
    {  
      var input = $(this);
      var type = input.prop('type') ;
      var name = input.attr('name') ;

      switch (type.substr(0,6))
      {
      case 'select':
      case 'text':
      case 'number':
      case 'date':
      case 'checkb':
      case 'textar':
      case 'email':
      case 'hidden':

        if ( type.substr(0,6) !== 'hidden' || ( type.substr(0,6) === 'hidden' && (name === 'table_row' || 
                                                                                  name === 'note_table_row') ) )
        {

          var value = input.val() ;
          if ( type == 'checkbox' ) 
          { 
            value = 0 ;   
            var temp =  input.prop('checked') ; 
            if ( temp !== false ) { value = 1  ; }  // The test seems to return 1 or '',  else false
          } 
          if ( name === 'wireless_no' && value.indexOf('(') !== -1 )
          {
            value = value.strip_phone_format() ;
          }
          if ( name === 'simm_identifier' || name === 'IMEI' || name === 'IMSI' )
          {
            value = value.replace(' ', '') ;
          }
          
          var orig_value = $('input[name=orig_'+name).val() ;
          if ( typeof orig_value === 'undefined') { orig_value = '' ; }
          
          // So PHP no burp w/o a value here
          if ( name === 'table_row' || name === 'note_table_row' )
          { orig_value = value ; } 
          
          var parent_table = input.data('tablename') ;  //   <-- c/o form input with data-tablename="somevalue" within its < input ></ input >
          if ( typeof parent_table === 'undefined' ) { parent_table = tablename ; }
          
          
          // More special circumstances
          
          
          
          // When updating a Note we do not want to update its referencing table
          if ( !updating_a_note || parent_table === 'Note' )
          {
            console.log('Type: ' + type + '    Name: ' + name + '    Value: ' + value + '   OrigValue: '+orig_value+'   tablename: '+parent_table );  

            var fieldSpecs = {} ;
            fieldSpecs['name'] = name ;
            fieldSpecs['type'] = type ;
            fieldSpecs['value'] = value ;
            fieldSpecs['orig_value'] = orig_value ;
            fieldSpecs['tablename'] = parent_table ;

            jArray.push(fieldSpecs) ;
          }
        }

Open in new window



Relevant console.log info (See lines 34 to 43 for the `note` textarea):
AJAXed to do_FormCommit_work.php for UpdateTableRecs(), data.status=undefined
Type: text    Name: wireless_no    Value: 4254207471   OrigValue: 4254207471   tablename: ModemConfig
Type: text    Name: serial_number    Value: U061664   OrigValue: U061664   tablename: ModemConfig
Type: text    Name: part_number    Value:    OrigValue:    tablename: ModemConfig
Type: text    Name: user_id    Value: 310410567660446@mascorp.com   OrigValue: 310410567660446@mascorp.com   tablename: ModemConfig
Type: text    Name: password    Value: 142006EF94D532F6   OrigValue: 142006EF94D532F6   tablename: ModemConfig
Type: text    Name: simm_identifier    Value: 89014102 2556 7660 0000    OrigValue: 89014102 2556 7660 0000    tablename: ModemConfig
Type: text    Name: IMEI    Value: 35322702 5915 226    OrigValue: 35322702 5915 226    tablename: ModemConfig
Type: text    Name: IMSI    Value: 310410 567 660 446    OrigValue: 310410 567 660 446    tablename: ModemConfig
Type: text    Name: IP_addr    Value: 10.145.8.235   OrigValue: 10.145.8.235   tablename: ModemConfig
Type: text    Name: assembly_id    Value: RD-AA8101-03   OrigValue: RD-AA8101-03   tablename: ModemConfig
Type: text    Name: type    Value: 2G   OrigValue: 2G   tablename: ModemConfig
Type: date    Name: date_activation    Value:    OrigValue:    tablename: ModemConfig
Type: date    Name: date_ship_confirm    Value:    OrigValue:    tablename: ModemConfig
Type: date    Name: date_into_service    Value:    OrigValue:    tablename: ModemConfig
Type: select-one    Name: billable_status    Value: Active   OrigValue: Active   tablename: ModemActivity
Type: select-one    Name: modem_utilization    Value: Select Utilization   OrigValue: Select Utilization   tablename: ModemActivity
Type: text    Name: modem_location    Value:    OrigValue:    tablename: ModemActivity
Type: date    Name: date_suspended    Value:    OrigValue:    tablename: ModemActivity
Type: date    Name: date_suspend_renew    Value:    OrigValue:    tablename: ModemActivity
Type: checkbox    Name: confgd_for_roaming    Value: 1   OrigValue: 1   tablename: ModemActivity
Type: select-one    Name: cust_name    Value: GE CAPITAL AVIATION SERVICES   OrigValue: GE CAPITAL AVIATION SERVICES   tablename: 
Type: text    Name: cust_desig_2char    Value:    OrigValue:    tablename: Customer
Type: text    Name: cust_desig_3char    Value:    OrigValue:    tablename: Customer
Type: text    Name: region    Value: Europe   OrigValue: Europe   tablename: Customer
Type: select-one    Name: aircraft_reg_no    Value: Select A/C Reg. No   OrigValue: Select A/C Reg. No   tablename: Aircraft
Type: text    Name: aircraft_type    Value: B737-800   OrigValue: B737-800   tablename: Aircraft
Type: select-one    Name: aircraft_status    Value: Select Aircraft Status   OrigValue: Select Aircraft Status   tablename: Aircraft
Type: text    Name: ife_system_type    Value:    OrigValue:    tablename: Aircraft
Type: text    Name: program_number    Value: CGA73814   OrigValue: CGA73814   tablename: Aircraft
Type: select-one    Name: domplan_code    Value: Select Domestic Plan   OrigValue: Select Domestic Plan   tablename: DomRatePlan
Type: select-one    Name: intlplan_code    Value: Select International Plan   OrigValue: Select International Plan   tablename: IntlRatePlan
Type: text    Name: ident_of_latest_drp_invoice    Value: Jun 2016 Modem Plans for current period   OrigValue: Jun 2016 Modem Plans for current period   tablename: DomRatePlan
Type: textarea    Name: note    Value: ------------------------------------------- don&apos;t 
[Tue Jul 19 2016 @ 15:15:02]   New.  Found on Jun 2016 Modem Plans for current period.
-------------------------------------------
[Tue Jul 19 2016 @ 15:27:04]   Found on Jun 2016 Modem Charges for prior period invoice.
-------------------------------------------
[Thu Jul 21 2016 @ 15:34:59] Data revision c/o Manufacturing list import.
OLD S/N = Unassigned                           OLD IMEI =                                     OLD IP Address =                               
OLD Assembly =                                 OLD Type =                                     OLD Date Activation = 0000-00-00               
OLD User ID =                                  OLD Password =                                 OLD SIMM ID =                                  
OLD IMSI =   OrigValue: -------------------------------------------[Tue Jul 19 2016 @ 15:15:02]   New.  Found on Jun 2016 Modem Plans for current period.-------------------------------------------[Tue Jul 19 2016 @ 15:27:04]   Found on Jun 2016 Modem Charges for prior period invoice.-------------------------------------------[Thu Jul 21 2016 @ 15:34:59] Data revision c/o Manufacturing list import.OLD S/N = Unassigned                           OLD IMEI =                                     OLD IP Address =                               OLD Assembly =                                 OLD Type =                                     OLD Date Activation = 0000-00-00               OLD User ID =                                  OLD Password =                                 OLD SIMM ID =                                  OLD IMSI =   tablename: Note
SOMETHING ELSE  Type: reset    Name: refresh_ModemALLTable    Value: Revert
SOMETHING ELSE  Type: button    Name: clear_ModemALLTable    Value: Clear
SOMETHING ELSE  Type: submit    Name: search_ModemALLTable    Value: Search
SOMETHING ELSE  Type: button    Name: makereminder_ModemALLTable    Value: Make Reminder
SOMETHING ELSE  Type: button    Name: Update    Value: Update
SOMETHING ELSE  Type: button    Name: New    Value: New
Type: hidden    Name: table_row    Value: 1483   OrigValue: 1483   tablename: ModemConfig
Type: hidden    Name: note_table_row    Value:    OrigValue:    tablename: ModemConfig
AJAXing to do_FormCommit_work.php with json array for Update.

Open in new window


From the $_POST-ed object sent to PHP to do the comparisons (cleaned up)
See the "\n" for the "value" but not "orig_value" in line 43:
posted:[
{"job":"SubmitForUpdate",
"object_list":["[0][job], [0][object_list]===this, [0][nFields]","[1][{formSpecs}]: USAGE: [1][formID], [1][parent_table]","[2][{table_ids}]: USAGE: [2][ModemConfig]=>modem_config_id, ...","[3]...[nFields][{fieldSpecs}]:  USAGE: [3][name], [3][type], [3][value], [3][orig_value], [3][tablename]","[3+nFields]...[?] [{pkValues}]:  USAGE: [n][name], [n][value]"],
"nFields":35},

{"formID":"PopulateModemALL",
"parent_table":"ModemConfig"},

{"ModemConfig":"modem_config_id","ModemActivity":"modem_activity_id","Customer":"customer_id","Aircraft":"aircraft_id","ServiceProvider":"service_provider_id","DomRatePlan":"dom_rate_plan_id","IntlRatePlan":"intl_rate_plan_id","Invoice":"invoice_id","InvoicedModem":"invoiced_modem_id","CreditRequest":"credit_request_id","CreditedModem":"credited_modem_id","Credit":"credit_id","Contact":"contact_id","ContactGroup":"contact_group_id","ModemSwap":"modem_config_id","Note":"note_id"},

{"name":"wireless_no","type":"text","value":"4254207471","orig_value":"4254207471","tablename":"ModemConfig"},
{"name":"serial_number","type":"text","value":"U061664","orig_value":"U061664","tablename":"ModemConfig"},
{"name":"part_number","type":"text","value":"","orig_value":"","tablename":"ModemConfig"},
{"name":"user_id","type":"text","value":"310410567660446@mascorp.com","orig_value":"310410567660446@mascorp.com","tablename":"ModemConfig"},
{"name":"password","type":"text","value":"142006EF94D532F6","orig_value":"142006EF94D532F6","tablename":"ModemConfig"},
{"name":"simm_identifier","type":"text","value":"89014102 2556 7660 0000 ","orig_value":"89014102 2556 7660 0000 ","tablename":"ModemConfig"},
{"name":"IMEI","type":"text","value":"35322702 5915 226 ","orig_value":"35322702 5915 226 ","tablename":"ModemConfig"},
{"name":"IMSI","type":"text","value":"310410 567 660 446 ","orig_value":"310410 567 660 446 ","tablename":"ModemConfig"},
{"name":"IP_addr","type":"text","value":"10.145.8.235","orig_value":"10.145.8.235","tablename":"ModemConfig"},
{"name":"assembly_id","type":"text","value":"RD-AA8101-03","orig_value":"RD-AA8101-03","tablename":"ModemConfig"},
{"name":"type","type":"text","value":"2G","orig_value":"2G","tablename":"ModemConfig"},
{"name":"date_activation","type":"date","value":"","orig_value":"","tablename":"ModemConfig"},
{"name":"date_ship_confirm","type":"date","value":"","orig_value":"","tablename":"ModemConfig"},
{"name":"date_into_service","type":"date","value":"","orig_value":"","tablename":"ModemConfig"},
{"name":"billable_status","type":"select-one","value":"Active","orig_value":"Active","tablename":"ModemActivity"},
{"name":"modem_utilization","type":"select-one","value":"Select Utilization","orig_value":"Select Utilization","tablename":"ModemActivity"},
{"name":"modem_location","type":"text","value":"","orig_value":"","tablename":"ModemActivity"},
{"name":"date_suspended","type":"date","value":"","orig_value":"","tablename":"ModemActivity"},
{"name":"date_suspend_renew","type":"date","value":"","orig_value":"","tablename":"ModemActivity"},
{"name":"confgd_for_roaming","type":"checkbox","value":1,"orig_value":"1","tablename":"ModemActivity"},
{"name":"cust_name","type":"select-one","value":"GE CAPITAL AVIATION SERVICES","orig_value":"GE CAPITAL AVIATION SERVICES","tablename":"Customer"},
{"name":"cust_desig_2char","type":"text","value":"","orig_value":"","tablename":"Customer"},
{"name":"cust_desig_3char","type":"text","value":"","orig_value":"","tablename":"Customer"},
{"name":"region","type":"text","value":"Europe","orig_value":"Europe","tablename":"Customer"},
{"name":"aircraft_reg_no","type":"select-one","value":"Select A/C Reg. No","orig_value":"Select A/C Reg. No","tablename":"Aircraft"},
{"name":"aircraft_type","type":"text","value":"B737-800","orig_value":"B737-800","tablename":"Aircraft"},
{"name":"aircraft_status","type":"select-one","value":"Select Aircraft Status","orig_value":"Select Aircraft Status","tablename":"Aircraft"},
{"name":"ife_system_type","type":"text","value":"","orig_value":"","tablename":"Aircraft"},
{"name":"program_number","type":"text","value":"CGA73814","orig_value":"CGA73814","tablename":"Aircraft"},
{"name":"domplan_code","type":"select-one","value":"Select Domestic Plan","orig_value":"Select Domestic Plan","tablename":"DomRatePlan"},
{"name":"intlplan_code","type":"select-one","value":"Select International Plan","orig_value":"Select International Plan","tablename":"IntlRatePlan"},
{"name":"ident_of_latest_drp_invoice","type":"text","value":"Jun 2016 Modem Plans for current period","orig_value":"Jun 2016 Modem Plans for current period","tablename":"DomRatePlan"},
{"name":"note","type":"textarea","value":"------------------------------------------- don&apos;t \n[Tue Jul 19 2016 @ 15:15:02]   New.  Found on Jun 2016 Modem Plans for current period.\n-------------------------------------------\n[Tue Jul 19 2016 @ 15:27:04]   Found on Jun 2016 Modem Charges for prior period invoice.\n-------------------------------------------\n[Thu Jul 21 2016 @ 15:34:59] Data revision c/o Manufacturing list import.\nOLD S/N = Unassigned                           OLD IMEI =                                     OLD IP Address =                               \nOLD Assembly =                                 OLD Type =                                     OLD Date Activation = 0000-00-00               \nOLD User ID =                                  OLD Password =                                 OLD SIMM ID =                                  \nOLD IMSI =","orig_value":"-------------------------------------------[Tue Jul 19 2016 @ 15:15:02]   New.  Found on Jun 2016 Modem Plans for current period.-------------------------------------------[Tue Jul 19 2016 @ 15:27:04]   Found on Jun 2016 Modem Charges for prior period invoice.-------------------------------------------[Thu Jul 21 2016 @ 15:34:59] Data revision c/o Manufacturing list import.OLD S/N = Unassigned                           OLD IMEI =                                     OLD IP Address =                               OLD Assembly =                                 OLD Type =                                     OLD Date Activation = 0000-00-00               OLD User ID =                                  OLD Password =                                 OLD SIMM ID =                                  OLD IMSI =","tablename":"Note"},
{"name":"table_row","type":"hidden","value":"1483","orig_value":"1483","tablename":"ModemConfig"},
{"name":"note_table_row","type":"hidden","value":"","orig_value":"","tablename":"ModemConfig"},

{"name":"modem_activity_id","value":"1483"},
{"name":"customer_id","value":"49"},
{"name":"aircraft_id","value":"1972"},
{"name":"dom_rate_plan_id","value":"2"},
{"name":"intl_rate_plan_id","value":"18"},
{"name":"note_id","value":"4484"},
{"name":"note_id","value":""}
]

Open in new window

As usual, thanks for the assistance.
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ralph

ASKER

Thanks Robert, that was it!