Skip to content

Commit

Permalink
because of CSP changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mlantz committed May 29, 2023
1 parent 13ff923 commit 06cfbe3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Fields/CustomFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected static function getOptions()
protected static function getAttributes()
{
return [
'data-formsjs-onchange' => '_formsjs_customfileField(this);'
'data-formsjs-onchange' => 'FormJS_customfileField(event)'
];
}

Expand All @@ -44,7 +44,7 @@ public static function getTemplate($options)
public static function js($id, $options)
{
return <<<JS
_formsjs_customfileField = function (input) {
window.FormJS_customfileField = function (input) {
input.nextElementSibling.innerHTML = input.files[0].name;
}
JS;
Expand Down
5 changes: 3 additions & 2 deletions src/Fields/FileWithPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected static function getType()
protected static function getAttributes()
{
return [
'data-formsjs-onchange' => '_formsjs_fileWithPreviewField(this);'
'data-formsjs-onchange' => 'FormJS_fileWithPreviewField(event)'
];
}

Expand Down Expand Up @@ -54,7 +54,8 @@ public static function js($id, $options)
}

return <<<JS
_formsjs_fileWithPreviewField = function (input) {
window.FormJS_fileWithPreviewField = function (event) {
let input = event.target;
if (! input.getAttribute('data-formsjs-rendered')) {
let _config = JSON.parse(input.getAttribute('data-formsjs-onload-data'));
let _method = function (e) { document.querySelector(_config.preview).setAttribute('src', e.target.result); };
Expand Down
13 changes: 13 additions & 0 deletions src/Services/FormAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ protected function compileScripts($type, $nonce = false)
window.Forms_validate_submission(event.target.form, '<i class=\"fas fa-circle-notch fa-spin mr-2\"></i> Save',event.target);
} else if (_method.includes('FormsJS_disableOnSubmit')) {
window.FormsJS_disableOnSubmit(event);
} else if (_method.includes('.')) {
let _path = _method.split('.');
if (_path.length == 2) {
window[_path[0]][_path[1]](event);
}
if (_path.length == 3) {
window[_path[0]][_path[1]][_path[2]](event);
}
if (_path.length == 4) {
throw new Error('Method nesting is too deep. Max of 3!');
}
} else if (typeof window[_method] === 'function') {
window[_method](event);
}
Expand Down

0 comments on commit 06cfbe3

Please sign in to comment.