Components / structured
SchemaForm view
A form built from a schema.
A view survives a frame. Hold it in an Entity with cx.new(..) and reach it with .update(..).
use gpui_kit::structured::SchemaForm;
Reviewed in schema-form.
Construct
new(ident: impl Into<Ident>, schema: Schema, window: &mut Window, cx: &mut Context<Self>) -> Self
Commands
Need a Context, so they need a view.
set_files(path: impl Into<SharedString>, files: Vec<PathBuf>, cx: &mut Context<Self>) -> Result<bool, SharedString>
add_list_item(path: impl Into<SharedString>, window: &mut Window, cx: &mut Context<Self>) -> bool
remove_list_item(path: impl Into<SharedString>, index: usize, cx: &mut Context<Self>) -> bool
move_list_item(path: impl Into<SharedString>, from: usize, to: usize, cx: &mut Context<Self>) -> bool
set_field_validation(path: impl Into<SharedString>, validation: ValidationState, cx: &mut Context<Self>) -> bool
clear_field_validation(path: impl Into<SharedString>, cx: &mut Context<Self>) -> bool
set_field_visibility(path: impl Into<SharedString>, visibility: FieldVisibility, cx: &mut Context<Self>) -> bool
set_validation(validation: ValidationState, cx: &mut Context<Self>)
clear_validation(cx: &mut Context<Self>)
set_error(path: impl Into<SharedString>, message: impl Into<SharedString>, cx: &mut Context<Self>)
clear_host_errors(cx: &mut Context<Self>)
validate(cx: &mut Context<Self>) -> bool
set_disabled(disabled: bool, cx: &mut Context<Self>)
Queries
Only answer; they change nothing.
field_validation(path: &str, cx: &App) -> Option<ValidationState>
field_visibility(path: &str, cx: &App) -> Option<FieldVisibility>
validation() -> Option<&ValidationState>
values(cx: &App) -> Vec<(SharedString, FieldValue)>
submission_values(cx: &App) -> Vec<(SharedString, FieldValue)>
unrenderable() -> &[UnrenderableField]
has_unrenderable_required() -> bool
Reports
The variants of the event it emits. It never applies the change itself.
- Changed
- FilesRequested
- Submitted
Example · schema-form
fn schema_form(window: &mut Window, cx: &mut App) -> AnyElement {
if !cx.has_global::<SceneSchemaForm>() {
set_schema_file_policy(DefaultSchemaFilePolicy, cx);
let form = cx.new(|cx| SchemaForm::new("scene.schema", scene_schema(), window, cx));
form.update(cx, |form, cx| {
// An error the host returned rather than one the form derived:
// only the host knows this path is outside the workspace.
form.set_error("path", "That path is outside the workspace.", cx);
let _ = form.set_field_validation("encoding", ValidationState::Validating, cx);
form.set_files("attachments", vec!["/workspace/brief.md".into()], cx)
.expect("the scene's permissive file policy accepts its fixture");
form.add_list_item("headers", window, cx);
});
cx.set_global(SceneSchemaForm { form });
}
let form = cx.global::<SceneSchemaForm>().form.clone();
let theme = cx.theme().clone();
stack(&theme).w(px(520.0)).child(form).into_any_element()
}