Skip to content

Commit 78fda39

Browse files
committed
Html data attributes are automatically encoded as JSON
1 parent cdf828c commit 78fda39

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/Forms/Controls/BaseControl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public function getControl()
253253
'id' => $this->getHtmlId(),
254254
'required' => $this->isRequired(),
255255
'disabled' => $this->isDisabled(),
256-
'data-nette-rules' => Nette\Forms\Helpers::exportRules($this->rules),
256+
'data-nette-rules' => Nette\Forms\Helpers::exportRules($this->rules) ?: NULL,
257257
));
258258
}
259259

src/Forms/Controls/SubmitButton.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function getControl($caption = NULL)
118118
}
119119
return parent::getControl($caption)->addAttributes(array(
120120
'formnovalidate' => $this->validationScope !== NULL,
121-
'data-nette-validation-scope' => $scope ? json_encode($scope) : NULL,
121+
'data-nette-validation-scope' => $scope ?: NULL,
122122
));
123123
}
124124

src/Forms/Helpers.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static function generateHtmlName($id)
9595
/**
9696
* @return array
9797
*/
98-
public static function exportRules(Rules $rules, $json = TRUE)
98+
public static function exportRules(Rules $rules)
9999
{
100100
$payload = array();
101101
foreach ($rules as $rule) {
@@ -108,7 +108,7 @@ public static function exportRules(Rules $rules, $json = TRUE)
108108
if ($rule->branch) {
109109
$item = array(
110110
'op' => ($rule->isNegative ? '~' : '') . $op,
111-
'rules' => static::exportRules($rule->branch, FALSE),
111+
'rules' => static::exportRules($rule->branch),
112112
'control' => $rule->control->getHtmlName()
113113
);
114114
if ($rule->branch->getToggles()) {
@@ -128,9 +128,7 @@ public static function exportRules(Rules $rules, $json = TRUE)
128128

129129
$payload[] = $item;
130130
}
131-
return $json
132-
? ($payload ? Nette\Utils\Json::encode($payload) : NULL)
133-
: $payload;
131+
return $payload;
134132
}
135133

136134

0 commit comments

Comments
 (0)