Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP If the model contains errors, display inline errors in jsoneditor #60

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

germanbisurgi
Copy link
Contributor

No description provided.

…he JSON editor to 'always' in order to exhibit inline errors upon initialization.
@germanbisurgi germanbisurgi changed the title If the model contains errors, display inline errors in jsoneditor WIP If the model contains errors, display inline errors in jsoneditor Feb 1, 2024
@schmunk42
Copy link
Member

@germanbisurgi Does this also prevent the form from being sent to the server in the first place?

…eClientValidation' => true.

It' s job is to collect and display inline validation errors within the json-editor form.
It also remove the added ".has-error" classes that Yii-2 adds everywhere in the json-editor indiscriminately.

public function clientValidateAttribute($model, $attribute, $view)
{
return <<<JS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work, when using multiple JSONEditor on the same Page?

Copy link
Contributor Author

@germanbisurgi germanbisurgi Mar 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ClientSideJsonValidator works with the first json-editor it finds. Currently, Widgets2 uses only one json-editor at a time.

The publication module relies on Widgets2 as a dependency, I manually tested it and found no errors. It's worth noting that the publication module doesn't actively use the ClientSideJsonValidator. Instead, relies on the the regular json-editor error messages during interaction.

If you have any potential scenarios that could conflict with this pull request, please let me know. I know this PR could create more issues than it solves :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an extra check for the editor. In any case, if for some reason an error occurs during this client validation step, The page will just submit the form normally (no AJAX) and proceed with the normal flow, meaning backend validation and showing an error summary

Copy link
Member

@schmunk42 schmunk42 Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ClientSideJsonValidator specific to widgets2 or would it actually belong to https://github.com/dmstr/yii2-json-editor ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is specific to widgets2

@germanbisurgi germanbisurgi requested a review from eluhr March 4, 2024 15:03
Copy link
Member

@schmunk42 schmunk42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
@eluhr @handcode WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants