From 0bf891d3ae6f84f655d7ee74acdd166ab5ba2615 Mon Sep 17 00:00:00 2001 From: Nate Wright Date: Thu, 24 May 2018 17:50:28 +0100 Subject: [PATCH] pkp/pkp-lib#3594 Initial implementation of Form component --- src/components/Form/Form.vue | 116 +++++++++++++++++++ src/components/Form/FormGroup.vue | 122 ++++++++++++++++++++ src/components/Form/FormPage.vue | 86 ++++++++++++++ src/components/Form/fields/FieldBase.vue | 140 +++++++++++++++++++++++ src/components/Form/fields/FieldText.vue | 50 ++++++++ src/docs/examples.js | 8 ++ src/docs/examples/Form/data.js | 84 ++++++++++++++ src/docs/examples/Form/notes.md | 2 + src/main.js | 10 ++ 9 files changed, 618 insertions(+) create mode 100644 src/components/Form/Form.vue create mode 100644 src/components/Form/FormGroup.vue create mode 100644 src/components/Form/FormPage.vue create mode 100644 src/components/Form/fields/FieldBase.vue create mode 100644 src/components/Form/fields/FieldText.vue create mode 100644 src/docs/examples/Form/data.js create mode 100644 src/docs/examples/Form/notes.md diff --git a/src/components/Form/Form.vue b/src/components/Form/Form.vue new file mode 100644 index 000000000..d7bfb91b6 --- /dev/null +++ b/src/components/Form/Form.vue @@ -0,0 +1,116 @@ + + + + + diff --git a/src/components/Form/FormGroup.vue b/src/components/Form/FormGroup.vue new file mode 100644 index 000000000..9ae66c1e3 --- /dev/null +++ b/src/components/Form/FormGroup.vue @@ -0,0 +1,122 @@ + + + + + diff --git a/src/components/Form/FormPage.vue b/src/components/Form/FormPage.vue new file mode 100644 index 000000000..38e8328f4 --- /dev/null +++ b/src/components/Form/FormPage.vue @@ -0,0 +1,86 @@ + + + diff --git a/src/components/Form/fields/FieldBase.vue b/src/components/Form/fields/FieldBase.vue new file mode 100644 index 000000000..5b428fe23 --- /dev/null +++ b/src/components/Form/fields/FieldBase.vue @@ -0,0 +1,140 @@ + + + diff --git a/src/components/Form/fields/FieldText.vue b/src/components/Form/fields/FieldText.vue new file mode 100644 index 000000000..d65fd7184 --- /dev/null +++ b/src/components/Form/fields/FieldText.vue @@ -0,0 +1,50 @@ + + + + + diff --git a/src/docs/examples.js b/src/docs/examples.js index 6b12b1eda..283645c72 100644 --- a/src/docs/examples.js +++ b/src/docs/examples.js @@ -4,6 +4,8 @@ import ViewButton from './examples/Button/ViewButton.vue'; import ButtonRaw from '!!raw-loader!@/components/Button/Button.vue'; import ViewIcon from './examples/Icon/ViewIcon.vue'; import IconRaw from '!!raw-loader!@/components/Icon/Icon.vue'; +import Form from '@/components/Form/Form.vue'; +import FormRaw from '!!raw-loader!@/components/Form/Form.vue'; import ViewList from './examples/List/ViewList.vue'; import ViewListRaw from '!!raw-loader!./examples/List/ViewList.vue'; import ListPanel from '@/components/ListPanel/ListPanel.vue'; @@ -24,6 +26,12 @@ export default { label: 'Button', url: '/components/Button', }, + Form: { + component: Form, + componentRaw: FormRaw, + label: 'Form', + url: '/components/Form', + }, Icon: { component: ViewIcon, componentRaw: IconRaw, diff --git a/src/docs/examples/Form/data.js b/src/docs/examples/Form/data.js new file mode 100644 index 000000000..826e75a23 --- /dev/null +++ b/src/docs/examples/Form/data.js @@ -0,0 +1,84 @@ +export default { + baseData: function () { + return { + id: 'viewForm', + action: '/example/1', + errors: [], + object: null, + fields: [ + { + name: 'name', + component: 'field-text', + inputType: 'text', + label: 'Name', + description: 'Please enter your full name.', + tooltip: '', + helpLink: '', + groupId: 'identity', + isMultilingual: false, + isRequired: true, + validateAs: '', + localeKey: 'en_US', + value: '', + }, + { + name: 'email', + component: 'field-text', + inputType: 'email', + label: 'Email', + description: '', + tooltip: '', + helpLink: '', + groupId: 'identity', + isMultilingual: false, + isRequired: true, + validateAs: '', + localeKey: 'en_US', + value: '', + }, + { + name: 'affiliation', + component: 'field-text', + inputType: 'text', + label: 'Affiliation', + description: 'Please enter the institution you are affiliated with.', + tooltip: '', + helpLink: '', + groupId: 'identity', + isMultilingual: false, + isRequired: true, + validateAs: '', + localeKey: 'en_US', + value: '', + }, + ], + groups: [{ + id: 'identity', + label: 'Identity', + description: 'Your name, email and institution will be displayed alongside any published works. We also use these details to communicate with you.', + pageId: 'viewForm', + }], + pages: [{ + id: 'viewForm', + submitOnNext: false, + }], + submitButton: { + label: 'Submit', + }, + activeLocales: ['en_US'], + }; + }, + dataDesc: { + id: 'Used internally. Do not modify.', + }, + propDescription: { + action: 'Where the form should be submitted. It accepts a full URL (`http://...`) or an endpoint (`submissions/1`).', + errors: 'Array of error messages, which may be added in the server or client.', + object: 'Optional. Pass an object, like a submission, to populate the form field values. Object properties will be mapped to field names. So `submission.title` will be set to the value of a field named `title`.', + fields: 'Array of form fields.', + groups: 'Array of form groups. Use these to group related fields.', + pages: 'Array of form pages.', + submitButton: 'Object representing the submit button. Pass any props supported by ``.', + activeLocales: 'The locale(s) the form is currently being presented in.', + }, +}; diff --git a/src/docs/examples/Form/notes.md b/src/docs/examples/Form/notes.md new file mode 100644 index 000000000..7c7bf94eb --- /dev/null +++ b/src/docs/examples/Form/notes.md @@ -0,0 +1,2 @@ + +Use this component to display a form. diff --git a/src/main.js b/src/main.js index 85896ad1c..6f2014f7b 100644 --- a/src/main.js +++ b/src/main.js @@ -62,6 +62,16 @@ window.$.pkp = { app: { currentLocale: 'en_US', primaryLocale: 'en_US', + formLocales: [ + { + key: 'en_US', + label: 'English', + }, + { + key: 'fr_CA', + label: 'Français (Canada)', + }, + ], }, };