@@ -179,7 +179,7 @@ PAYPAL.apps = PAYPAL.apps || {};
179179
180180 css += paypalButton + ' .field-error { border: 1px solid #FF0000; }' ;
181181 css += paypalButton + ' .hide { display: none; }' ;
182- css += paypalButton + ' .error-box { background: none repeat scroll 0 0 #EEEEEE ; border: 1px solid #DADADA; border-radius: 5px; padding: 8px; display: inline-block; }' ;
182+ css += paypalButton + ' .error-box { background: #FFFFFF; verflow: scroll; border: 1px solid #DADADA; border-radius: 5px; padding: 8px; display: inline-block; }' ;
183183
184184 css += paypalInput + ' { white-space: nowrap; overflow: hidden; border-radius: 13px; font-family: "Arial", bold, italic; font-weight: bold; font-style: italic; border: 1px solid #ffa823; color: #0E3168; background: #ffa823; position: relative; text-shadow: 0 1px 0 rgba(255,255,255,.5); cursor: pointer; z-index: 0; }' ;
185185 css += paypalInput + ':before { content: " "; position: absolute; width: 100%; height: 100%; border-radius: 11px; top: 0; left: 0; background: #ffa823; background: -webkit-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: -moz-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: -ms-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); z-index: -2; }' ;
@@ -277,18 +277,8 @@ PAYPAL.apps = PAYPAL.apps || {};
277277 for ( key in optionFieldArr ) {
278278 item = optionFieldArr [ key ] ;
279279 if ( optionFieldArr [ key ] . hasOptions ) {
280-
281- //IE8 >= Works fine
282- if ( typeof JSON === "object" && JSON !== null ) {
283- //Create Options Fields
284- fieldDetails = JSON . parse ( item . value ) ;
285- } else {
286- //For IE7 display input field
287- fieldDetails . value = '' ;
288- fieldDetails . label = '' ;
289- fieldDetails . key = item . key ;
290- }
291- if ( fieldDetails . value instanceof Array && typeof JSON === "object" && JSON !== null ) {
280+ fieldDetails = item . value ;
281+ if ( fieldDetails . options . length > 1 ) {
292282 input = hidden . cloneNode ( true ) ;
293283 //on - Option Name
294284 input . name = 'on' + item . displayOrder ;
@@ -298,8 +288,8 @@ PAYPAL.apps = PAYPAL.apps || {};
298288 //os - Option Select
299289 selector . name = 'os' + item . displayOrder ;
300290
301- for ( fieldDetail in fieldDetails . value ) {
302- fieldValue = fieldDetails . value [ fieldDetail ] ;
291+ for ( fieldDetail in fieldDetails . options ) {
292+ fieldValue = fieldDetails . options [ fieldDetail ] ;
303293 if ( typeof fieldValue === 'string' ) {
304294 optionField = optionElem . cloneNode ( true ) ;
305295 optionField . value = fieldValue ;
@@ -322,7 +312,7 @@ PAYPAL.apps = PAYPAL.apps || {};
322312 label . appendChild ( input ) ;
323313 } else {
324314 label = labelElem . cloneNode ( true ) ;
325- labelText = fieldDetails . label || fieldDetails . key ;
315+ labelText = fieldDetails . label || item . key ;
326316 label . htmlFor = item . key ;
327317 label . appendChild ( document . createTextNode ( labelText ) ) ;
328318
@@ -333,7 +323,7 @@ PAYPAL.apps = PAYPAL.apps || {};
333323
334324 input = inputTextElem . cloneNode ( true ) ;
335325 input . name = 'os' + item . displayOrder ;
336- input . value = fieldDetails . value ;
326+ input . value = fieldDetails . options [ 0 ] || '' ;
337327 input . setAttribute ( 'data-label' , fieldDetails . label ) ;
338328
339329 if ( fieldDetails . required ) {
@@ -396,9 +386,7 @@ PAYPAL.apps = PAYPAL.apps || {};
396386 if ( ! checkField ( field ) ) {
397387 errors . push ( validateFieldHandlers . required . message . replace ( '%s' , fieldLabel ) ) ;
398388 field . className = field . className + ' field-error' ;
399- } else if ( ! checkPattern ( field , patternName ) )
400- {
401- field . className = field . className + ' field-error' ;
389+ } else if ( ! checkPattern ( field , patternName ) ) {
402390 errors . push ( validateFieldHandlers [ patternName ] . message . replace ( '%s' , fieldLabel ) ) ;
403391 }
404392 }
@@ -418,8 +406,8 @@ PAYPAL.apps = PAYPAL.apps || {};
418406 function checkField ( field ) {
419407 if ( field . getAttribute ( 'data-required' ) )
420408 {
421- field . value = field . value . trim ( ) ;
422- return ! ( ! field . value || field . value === '' || field . value === undefined ) ;
409+ field . value = field . value ? field . value . trim ( ) : '' ;
410+ return ! ( field . value === '' ) ;
423411 }
424412 return true ;
425413 }
@@ -433,6 +421,7 @@ PAYPAL.apps = PAYPAL.apps || {};
433421 var validateData = validateFieldHandlers [ patternName ] ;
434422 if ( patternKey && validateData ) {
435423 pattern = new RegExp ( validateData . regex ) ;
424+ field . className = field . className + ' field-error' ;
436425 return pattern . test ( field . value ) ;
437426 }
438427 return true ;
@@ -442,11 +431,11 @@ PAYPAL.apps = PAYPAL.apps || {};
442431 * Display all error message
443432 */
444433 function displayErrorMsg ( errors ) {
445- var errMsg = '' ;
434+ var errMsg = '<ul> ' ;
446435 for ( var i = 0 ; i < errors . length ; i ++ ) {
447- errMsg += errors [ i ] + "<br/ >" ;
436+ errMsg += "<li>" + errors [ i ] + "</li >" ;
448437 }
449- return errMsg ;
438+ return errMsg + "</ul>" ;
450439 }
451440
452441 /**
@@ -496,12 +485,27 @@ PAYPAL.apps = PAYPAL.apps || {};
496485 * @return {Object }
497486 */
498487 function getDataSet ( el ) {
499- var dataset = { } , attrs , attr , matches , len , i ;
500-
488+ var dataset = { } , attrs , attr , matches , len , i , j ;
489+ var customFieldMap = { } , customSelectMap = { } , optionCount = 0 , valueCount = { } , optionArray = [ ] , optionMap = { } ;
501490 if ( ( attrs = el . attributes ) ) {
502491 for ( i = 0 , len = attrs . length ; i < len ; i ++ ) {
503492 attr = attrs [ i ] ;
504- if ( ( matches = attr . name . match ( / ^ d a t a - ( [ a - z 0 - 9 _ ] + ) ( - o p t i o n s ) - ( [ 0 - 9 ] ) ? / i) ) ) {
493+ if ( ( matches = attr . name . match ( / ^ d a t a - O P T I O N ( [ 0 - 9 ] ) ( [ a - z ] + ) ? / i) ) ) {
494+ if ( matches [ 2 ] === 'name' ) {
495+ optionCount ++ ;
496+ }
497+ dataset [ "option_" + matches [ 1 ] ] = {
498+ value : '' ,
499+ hasOptions : true ,
500+ displayOrder : parseInt ( matches [ 1 ] , 10 )
501+ } ;
502+ customFieldMap [ "value_" + matches [ 1 ] + "_" + matches [ 2 ] ] = attr . value ;
503+ } else if ( ( matches = attr . name . match ( / ^ d a t a - L _ O P T I O N ( [ 0 - 9 ] ) ( [ a - z ] + ) ( [ 0 - 9 ] ) ? / i) ) ) {
504+ if ( matches [ 2 ] === 'select' ) {
505+ valueCount [ matches [ 1 ] ] = ( valueCount [ matches [ 1 ] ] ? valueCount [ matches [ 1 ] ] + 1 : 1 ) ;
506+ }
507+ customSelectMap [ "dropdown_" + matches [ 1 ] + "_option_" + matches [ 2 ] + "_" + matches [ 3 ] ] = attr . value ;
508+ } else if ( ( matches = attr . name . match ( / ^ d a t a - ( [ a - z 0 - 9 _ ] + ) ( - o p t i o n s ) - ( [ 0 - 9 ] ) ? / i) ) ) {
505509 dataset [ matches [ 1 ] ] = {
506510 value : attr . value ,
507511 hasOptions : ! ! matches [ 2 ] ,
@@ -515,10 +519,24 @@ PAYPAL.apps = PAYPAL.apps || {};
515519 }
516520 }
517521 }
522+
523+ for ( i = 0 ; i < optionCount ; i ++ ) {
524+ optionArray = [ ] ;
525+ for ( j = 0 ; j < valueCount [ i ] ; j ++ ) {
526+ optionMap = { } ;
527+ if ( customSelectMap [ "dropdown_" + i + "_option_price_" + j ] === undefined ) {
528+ optionArray . push ( customSelectMap [ "dropdown_" + i + "_option_select_" + j ] ) ;
529+ } else {
530+ optionMap [ customSelectMap [ "dropdown_" + i + "_option_select_" + j ] ] = customSelectMap [ "dropdown_" + i + "_option_select_" + j ] + " " + customSelectMap [ "dropdown_" + i + "_option_price_" + j ] ;
531+ optionArray . push ( optionMap ) ;
532+ }
533+ }
534+ dataset [ 'option_' + i ] . value = { "options" : '' , "label" : customFieldMap [ "value_" + i + "_name" ] , "required" : customFieldMap [ "value_" + i + "_required" ] , "pattern" : customFieldMap [ "value_" + i + "_pattern" ] } ;
535+ dataset [ 'option_' + i ] . value . options = optionArray ;
536+ }
518537 return dataset ;
519538 }
520539
521-
522540 /**
523541 * A storage object to create structured methods around a button's data
524542 */
@@ -555,7 +573,6 @@ PAYPAL.apps = PAYPAL.apps || {};
555573 data = node && getDataSet ( node ) ;
556574 type = data && data . button && data . button . value ;
557575 business = node . src . split ( '?merchant=' ) [ 1 ] ;
558- //buttonId = data && data.button_id && data.button_id.value;
559576
560577 if ( business ) {
561578 ButtonFactory . create ( business , data , type , node . parentNode ) ;
0 commit comments