Skip to content

Commit 0b3050f

Browse files
authored
Merge pull request #1856 from z-song/1.5
1.5
2 parents cdb0a62 + 4c6ff67 commit 0b3050f

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/Form/Field/Mobile.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Mobile extends Text
1919

2020
public function render()
2121
{
22-
$options = json_encode($this->options);
22+
$options = $this->json_encode_options($this->options);
2323

2424
$this->script = <<<EOT
2525
@@ -31,4 +31,30 @@ public function render()
3131

3232
return parent::render();
3333
}
34+
35+
protected function json_encode_options($options)
36+
{
37+
$value_arr = [];
38+
$replace_keys = [];
39+
40+
foreach ($options as $key => &$value) {
41+
// Look for values starting with 'function('
42+
if (strpos($value, 'function(') === 0) {
43+
// Store function string.
44+
$value_arr[] = $value;
45+
// Replace function string in $foo with a 'unique' special key.
46+
$value = '%'.$key.'%';
47+
// Later on, we'll look for the value, and replace it.
48+
$replace_keys[] = '"'.$value.'"';
49+
}
50+
}
51+
52+
// Now encode the array to json format
53+
$json = json_encode($options);
54+
55+
// Replace the special keys with the original string.
56+
$json = str_replace($replace_keys, $value_arr, $json);
57+
58+
return $json;
59+
}
3460
}

0 commit comments

Comments
 (0)