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

Allow marking complete form as disabled / read only #854

Closed
1 task done
k-nut opened this issue Feb 28, 2018 · 9 comments
Closed
1 task done

Allow marking complete form as disabled / read only #854

k-nut opened this issue Feb 28, 2018 · 9 comments

Comments

@k-nut
Copy link

k-nut commented Feb 28, 2018

Prerequisites

Description

I would like to be able to render a complete form readonly or disabled. This is to show it to users later as a validation step. As far as I can tell this is not possible right now and I would have to add the respective property (ui:disabled/ui:readonly) for each input in the UISchema.

Would you agree that it might be useful to just set this globally on the form? If so I'd start preparing a pull request for it.

@glasserc
Copy link
Contributor

glasserc commented Mar 7, 2018

I don't have a strong opinion about this. The standard HTML form controls support readonly and disabled, but only on form controls, not on the form element itself. I don't know if we should try to be doing anything more powerful than the underlying HTML abstraction does. I almost feel like we should be making it easier to perform other kinds of global transformations on schemas, perhaps by exporting utility functions that allow users to map over a schema to produce a UI schema or something?

@ojab
Copy link
Contributor

ojab commented Mar 12, 2018

I'm also interested in this, it's useful for displaying whole form with only some fields enabled based on various conditions.
Basically it means that props.disabled || uiSchema["ui:disabled"] order should be changed here.

Maybe hide it behind some uiSchema flag, so it will not break current behaviour?

@k-nut
Copy link
Author

k-nut commented Apr 1, 2018

Now thinking about it again I think that I agree that it would make sense to not implement it like this but instead make it easier to generate a uiSchema from the schema or something like that. For the time being let me close this issue.

@k-nut k-nut closed this as completed Apr 1, 2018
@eberkund
Copy link

I am trying to make a view mode which displays the data but does not allow editing. So far I've gone with something like this,

Object.keys(schema.properties).map(function (key, index) {
    uiSchema[key] = {'ui:readonly': true};
});

I think going beyond standard HTML controls is necessary because the whole form is getting rendered by this component. Unless there is a way to disable or remove the 'Submit' button that I am not seeing.

IMO having a readonly attribute on the form could remove the submit button and set all the inner controls to readonly as well sort of like a display mode.

@comwt
Copy link

comwt commented Sep 13, 2018

For anyone looking into this in the future, the originally desired behavior (that of making the entire form readonly) can easily be accomplished, as follows:
uiSchema = { "ui:readonly": true }
No need to parse each property name of a JSON doc.

@eberkund
Copy link

@comwt Does that remove the submit button?

@YingXue
Copy link

YingXue commented Oct 26, 2018

@comwt Does that remove the submit button?

I tried it and it didn't disable or remove submit button. Also trying to figure out a way to do so...

@glasserc
Copy link
Contributor

This got implemented eventually anyhow as #1056.

@epicfaace
Copy link
Member

@eberkund @YingXue If you need to remove the submit button, you can just pass an empty div to the <Form> component: https://github.com/mozilla-services/react-jsonschema-form#form-action-buttons

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

7 participants