Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit 3642b37

Browse files
authored
Fixed double close
1 parent f634ea4 commit 3642b37

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

Sources/AdminPanel/Support/LeafTags/FormCheckboxGroup.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class FormCheckboxGroup: BasicTag {
1515
public func run(arguments: [Argument]) throws -> Node? {
1616

1717
/*
18-
#form:checkboxgroup(key, value, fieldset)
18+
#form:checkboxgroup(key, value, fieldset, attr1, attr2 etc)
1919

2020
Arguments:
2121
[0] = The name of the input (the key that gets posted) *
@@ -37,8 +37,6 @@ public class FormCheckboxGroup: BasicTag {
3737
)
3838
], requiring: ["send_mail"])
3939

40-
#form:checkboxgroup("send_mail", send_mail, fieldset)
41-
4240
expected output if fieldset is valid and value resolves to true:
4341
<div class="form-group">
4442
<div class="checkbox">
@@ -70,7 +68,7 @@ public class FormCheckboxGroup: BasicTag {
7068
</div>
7169
*/
7270

73-
guard arguments.count == 3,
71+
guard arguments.count >= 3,
7472
let inputName: String = arguments[0].value?.string,
7573
let fieldsetNode = arguments[2].value?.nodeObject
7674
else {
@@ -103,11 +101,23 @@ public class FormCheckboxGroup: BasicTag {
103101
template.append("<label>")
104102

105103
if(inputValue == true) {
106-
template.append("<input type='checkbox' id='\(inputName)' name='\(inputName)' value='\(inputName)' checked/>")
104+
template.append("<input type='checkbox' id='\(inputName)' name='\(inputName)' value='\(inputName)' checked")
107105
} else {
108-
template.append("<input type='checkbox' id='\(inputName)' name='\(inputName)' value='\(inputName)'/>")
106+
template.append("<input type='checkbox' id='\(inputName)' name='\(inputName)' value='\(inputName)'")
107+
}
108+
109+
// Add custom attributes
110+
if arguments.count > 3 {
111+
let max = arguments.count - 1
112+
for index in 3 ... max {
113+
if let argument = arguments[index].value?.string {
114+
template.append(" " + argument)
115+
}
116+
}
109117
}
110118

119+
template.append("/>")
120+
111121
template.append("\(label)")
112122

113123
template.append("</label>")

0 commit comments

Comments
 (0)