Skip to content

Commit de826f7

Browse files
author
Eduardo Parada
committed
Update: Repaired swift code and web working
1 parent 5b2324d commit de826f7

23 files changed

+639
-426
lines changed

Application/Json/json_formulary.json

+47-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,53 @@
55
"label": "titulo1 compare"
66
},
77
{
8+
"style": {
9+
"checkBox": {
10+
"checkBoxOff": "checkBoxOff_JR",
11+
"checkBoxOn": "checkBoxOn_JR"
12+
},
13+
"mandatoryIcon": "mandatory_JR ",
14+
"styleCell": "line "
15+
},
16+
"schemaId": "communicationOpts",
17+
"show": "checkbox",
18+
"type": "boolean",
19+
"key": "key1ssssss",
20+
"label": "I want to receive Coca-Cola communications",
21+
22+
"validator": [
23+
{
24+
"type": "bool",
25+
"textError": "Text error",
26+
}
27+
]
28+
},
29+
{
30+
"style": {
31+
"checkBox": {
32+
"checkBoxOff": "checkBoxOff_JR",
33+
"checkBoxOn": "checkBoxOn_JR"
34+
},
35+
"mandatoryIcon": "mandatory_JR ",
36+
"styleCell": "line "
37+
},
38+
"schemaId": "communicationOpts",
39+
"show": "checkbox",
40+
"type": "boolean",
41+
"key": "keyddddd2",
42+
"label": "I want to receive Coca-Cola communications",
43+
"validator": [
44+
{
45+
"type": "bool",
46+
"textError": "Text error",
47+
},
48+
{
49+
"type": "mandatory",
50+
"textError": "texto error mandatory"
51+
}
52+
]
53+
},
54+
{
855
"key": "key2",
956
"type": "text",
1057
"label": "titulo2 compare",
@@ -82,7 +129,6 @@
82129
"key": "keydatePicker",
83130
"type": "datePicker",
84131
"label": "tituloDatePicker t",
85-
"textError": "error_generic_field",
86132
"rules": {
87133
"fieldReciver": ["keyHiddenText", "keyHiddenText2"],
88134
"compare": ">",

GIGFormulary/Source/Validators/DNINIEValidator.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ class DNINIEValidator: StringValidator {
1717
let stringValue = value as? String
1818

1919
if stringValue != nil {
20-
return self.isValidNieNif(stringValue!)
20+
if !self.mandatory && stringValue?.count == 0 {
21+
return true
22+
} else {
23+
return self.isValidNieNif(stringValue!)
24+
}
2125
}
2226

2327
return true

GIGFormulary/Source/Validators/MandatoryValidator.swift

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class MandatoryValidator: StringValidator {
1313

1414
override func validate(_ value: Any?) -> Bool {
1515
if !super.validate(value) {
16+
if value is Bool {
17+
guard let valueBool = value as? Bool else {LogWarn("Parse value Bool Error, return false"); return false }
18+
return valueBool
19+
}
1620
return false
1721
} else {
1822
return true

GIGFormulary/Source/Validators/RegexValidator.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ class RegexValidator: StringValidator {
4545
if value != nil {
4646
guard let stringValue = value as? String else { LogWarn("Parse value String Error, return false"); return false }
4747
guard let regex = self.regex else { LogWarn("Regex is nil"); return false }
48-
49-
return regex.matchesString(stringValue)
48+
if stringValue.count == 0 && !self.mandatory {
49+
return true
50+
} else {
51+
return regex.matchesString(stringValue)
52+
}
5053
} else {
5154
return true
5255
}

GIGFormularyTests/Json/fomr2Compare.json

+20-7
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,31 @@
44
"key": "k1",
55
"type": "text",
66
"label": "t1",
7-
"mandatory": true
7+
"validator": [
8+
{
9+
"type": "mandatory",
10+
"textError": "texto error mandatory"
11+
}
12+
]
813
},
914
{
1015
"key": "k2",
11-
"mandatory": true,
1216
"type": "text",
1317
"label": "t2",
14-
"compare": true,
15-
"itemsCompare": [
16-
"k1", "k2"
17-
],
18-
"textErrorCompare": "texto error compare"
18+
"validator": [
19+
{
20+
"type": "compare",
21+
"textError": "texto error compare",
22+
"itemsCompare": [
23+
"key1",
24+
"key2"
25+
]
26+
},
27+
{
28+
"type": "mandatory",
29+
"textError": "texto error mandatory"
30+
}
31+
]
1932
}
2033
]
2134
}

GIGFormularyTests/Json/form1.json

+34-24
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,47 @@
77
"isEditing": true,
88
"isHidden": true,
99
"isPassword": true,
10-
"compare": true,
11-
"itemsCompare": [
12-
"a"
13-
],
14-
"textErrorCompare": "error",
1510
"style": {
16-
"backgroundColorField": "#5091ff",
17-
"titleColor": "#72ff97",
18-
"errorColor": "#ff303b",
19-
"sizeTitle": 12,
20-
"sizeError": 31,
21-
"align": "alignLeft",
22-
"font": "AmericanTypewriter",
23-
"mandatoryIcon": "imagenMandatory"
11+
"backgroundColorField": "#5091ff",
12+
"titleColor": "#72ff97",
13+
"errorColor": "#ff303b",
14+
"sizeTitle": 12,
15+
"sizeError": 31,
16+
"align": "alignLeft",
17+
"font": "AmericanTypewriter",
18+
"mandatoryIcon": "imagenMandatory"
19+
},
20+
"validator": [
21+
{
22+
"type": "compare",
23+
"textError": "error",
24+
"itemsCompare": ["a"]
25+
}
26+
],
27+
2428
}
2529
},
2630
{
2731
"isHidden": true,
28-
"mandatory": false,
2932
"style": {
30-
"checkBox": {
31-
"checkBoxOff": "checkBoxOff_JR",
32-
"checkBoxOn": "checkBoxOn_JR"
33-
},
33+
"checkBox": {
34+
"checkBoxOff": "checkBoxOff_JR",
35+
"checkBoxOn": "checkBoxOn_JR"
36+
},
3437
"mandatoryIcon": "mandatory_JR ",
3538
"styleCell": "line "
3639
},
37-
38-
"validator": "bool",
3940
"schemaId": "communicationOpts",
40-
"textError": "This field not could be empty",
4141
"show": "checkbox",
4242
"type": "boolean",
4343
"key": "key1",
44-
"label": "I want to receive Coca-Cola communications"
45-
44+
"label": "I want to receive Coca-Cola communications",
45+
"validator": [
46+
{
47+
"type": "bool",
48+
"textError": "Text error",
49+
}
50+
]
4651
},
4752
{
4853
"key": "key2",
@@ -61,7 +66,12 @@
6166
"type": "text",
6267
"label": "a2",
6368
"placeHolder": "a2",
64-
"mandatory": true
69+
"validator": [
70+
{
71+
"type": "mandatory",
72+
"textError": "texto error mandatory"
73+
}
74+
]
6575
},
6676
{
6777
"key": "key5",

GIGFormularyTests/Validator/RegexValidatorTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class RegexValidatorTests: XCTestCase {
8585
}
8686

8787
func test_validate_optional() {
88-
self.validator.mandatory = false
88+
self.validator = RegexValidator(regexPattern: ".{3}", mandatory: false)
8989

9090
XCTAssertTrue(self.validator.validate(nil))
9191
XCTAssertTrue(self.validator.validate(""))

0 commit comments

Comments
 (0)