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

Disable mode drop down if contnents are invalid json #1364

Closed
yogeshmahajan-1903 opened this issue Aug 19, 2021 · 10 comments
Closed

Disable mode drop down if contnents are invalid json #1364

yogeshmahajan-1903 opened this issue Aug 19, 2021 · 10 comments

Comments

@yogeshmahajan-1903
Copy link

Steps to reproduce -
1.Enter valid json content.
2.Delete some semicolon in order to create invalid json.
3.Try to change mode.
4.Console shows error.
Screenshot 2021-08-19 at 2 37 25 PM

Expected - Mode drop down should be disabled if contents are invalid json

@yogeshmahajan-1903
Copy link
Author

I think not only mode drop but also all operation buttons should be disabled except 'Repair Json'

@josdejong
Copy link
Owner

josdejong commented Aug 25, 2021

In text mode, when the text contents is no valid, parsable JSON, various features cannot be executed: expand, collapse, switch to tree mode, ...

When you try to execute those actions, an error will be thrown. By default, this error is logged in the console only. You can catch the error yourself and do something alternative, like presenting the error to the user in a modal or something like that:

const options = {
  onError: function (err) {
      alert(err.toString())
    }
}

Thinking about it, it may be better default behavior to show such a basic alert to the user on error instead of logging in the console.

In general I try to be careful with disabling buttons: it's easily not clear for a user why a button is disabled and what the user needs to do to get it enabled, so showing an explanatory error to the user when an action cannot be performed has my preference.

josdejong added a commit that referenced this issue Aug 25, 2021
…nstead of logging the error in the console (see #1364).
@josdejong
Copy link
Owner

I've changed the default behavior to open a basic alert when an error occurs, see cbb95ae

@yogeshmahajan-1903
Copy link
Author

Showing error will be more useful.
I have used onError(), but this works only for format & compact json buttons in Code mode.
For other buttons like transform, sort (in cod emode) still error is logged to console.

@josdejong
Copy link
Owner

For other buttons like transform, sort (in cod emode) still error is logged to console.

Hm, that should not be the case. I'll double check it

@josdejong
Copy link
Owner

You're right. I'll fix that.

@yogeshmahajan-1903
Copy link
Author

Thanks :)

josdejong added a commit that referenced this issue Aug 25, 2021
…N contents not triggering the `onError` callback (see #1364)
@josdejong
Copy link
Owner

Fixed via b3b31f2 (not yet published)

@josdejong
Copy link
Owner

Fixes/improvements are published now in v9.5.4

@yogeshmahajan-1903
Copy link
Author

Now error is shown in alert box instead of console.

andyquinterom pushed a commit to proyais/jsoneditor that referenced this issue Dec 7, 2021
andyquinterom pushed a commit to proyais/jsoneditor that referenced this issue Dec 7, 2021
…N contents not triggering the `onError` callback (see josdejong#1364)
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

No branches or pull requests

2 participants