This repository was archived by the owner on Feb 27, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,31 @@ function getCheckboxDefaults(checkboxes) {
25
25
return checkboxDefault
26
26
}
27
27
28
+ /**
29
+ * Assign default values for GravityForm Select.
30
+ *
31
+ * @param {Array } options Array of select option data Objects.
32
+ * @return {string } Select option value that is selected.
33
+ */
34
+ function getSelectDefaults ( options ) {
35
+ let selectDefault = ''
36
+
37
+ if ( ! options . length > 0 ) {
38
+ return selectDefault
39
+ }
40
+
41
+ /**
42
+ * Get first option with isSelected property.
43
+ */
44
+ const selectedOption = [ ] . filter ( ( option ) => ! ! option . isSelected ) . shift ( )
45
+
46
+ if ( selectedOption ) {
47
+ selectDefault = selectedOption . shift ( ) . value
48
+ }
49
+
50
+ return selectDefault
51
+ }
52
+
28
53
/**
29
54
* Match field type with a default value.
30
55
*
@@ -41,6 +66,10 @@ function getFieldDefaultByType(fieldData) {
41
66
defaultValue = getCheckboxDefaults ( fieldData ?. checkboxChoices )
42
67
break
43
68
69
+ case 'select' :
70
+ defaultValue = getSelectDefaults ( fieldData ?. selectChoices )
71
+ break
72
+
44
73
default :
45
74
defaultValue = fieldData ?. defaultValue
46
75
}
You can’t perform that action at this time.
0 commit comments