Socket
Socket
Sign inDemoInstall

@nhuson/react-dynamic-forms

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nhuson/react-dynamic-forms

Dynamic forms library for React


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

import { Form, Schema, Field, Chooser, TextEdit, formGroup, formList, FormEditStates } from "@nhuson/react-dynamic-forms";

class EmailForm extends React.Component { static defaultValues = { id: 2, amount: 1 };

static schema = (
    <Schema>
        <Field
            name="amount"
            defaultValue=""
            label="amount"
            required={true}
        />
        <Field name="id" defaultValue={1} label="Type" required={true} />
    </Schema>
);

emailTypes() {
    return Immutable.fromJS([{ id: 1, label: "Onion" }, { id: 2, label: "Lemon" }]);
}

emailTypeLabel() {
    let result;
    this.emailTypes().forEach(obj => {
        if (obj.id === this.props.value.get("id")) {
            result = obj.label;
        }
    });
    return result;
}

render() {
    const {
        onChange,
        onMissingCountChange,
        value = EmailForm.defaultValues
    } = this.props;
    const callbacks = { onChange, onMissingCountChange };
    if (this.props.edit) {
        return (
            <Form
                name={this.props.name}
                schema={EmailForm.schema}
                value={value}
                edit={FormEditStates.ALWAYS}
                labelWidth={50}
                {...callbacks}
            >
                <Chooser
                    field="id"
                    choiceList={this.emailTypes()}
                    disableSearch={false}
                    width={150}
                    value={1}
                />
                <TextEdit field="amount" width={300} />
            </Form>
        );
    } else {
        return (
            <Form
                name={this.props.name}
                schema={EmailForm.schema}
                value={value}
                edit={FormEditStates.TABLE}
                labelWidth={50}
                {...callbacks}
            >
                <TextEdit field="amount" width={250} />
                <Chooser
                    field="id"
                    choiceList={this.emailTypes()}
                    disableSearch={false}
                    width={250}
                    value={1}
                />
            </Form>
        );
    }
}

}

const EmailList = formList(EmailForm); const Ingredients = formGroup(EmailList);

Keywords

FAQs

Package last updated on 22 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc