Ashutosh Khanduala
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Form Builder WebApp - DATOMS ## packages that will be used - [react-draggable](https://www.npmjs.com/package/react-draggable) for draggable components - scss (for styled components) - react-helment (for seo) - Other Packages (All packages present in FormController/index.js) ## File structure of the new project ```tree src/components/ | |--- src/pages/ | |---FormBuilder | |---form-builder.scss |---index.jsx |---components |----FormController/ //will be entirely copied from the datoms_react_components project | |-index.js | |-style.scss | |-DefaultConfigs.js | |--FormComponentsMenu.jsx |--AccesibilityMenu.jsx ``` ## FormBuilder.jsx - The UI will have 3 different parts - Form Components Menu (its code will be present in FormComponentsMenu.jsx) - A "middle area" for viewing the form. (its code will be present in FormBuilder.jsx only) - Accesibility Menu (its code will be present in AccesibilityMenu.jsx) - It will have two child components:- FormComponentsMenu.jsx & AccesibilityMenu.jsx - the "middle area" will render FormController compononent. ```jsx <FormController json={json} onCallback={onCallback} /> // onCallback is function. const onCallback = (err, values) => { if (err) { console.log('onCallback: Error'); console.log(err); } else { console.log('onCallback: Success'); console.log(values); } }; // the variable json is defined below. Its a useState hook. ``` - It will use a useState hook named **json** to store the json that is responsible to render the whole form in the middle area - Whenever the JSON is modified by putting new components in the "middle-area" or by manipulating any one component, the whole FormBuilder component will be re-rendered to show the new UI obtained from that new modified JSON. - initialValue of **json** variable (useState hook) will be ```json json = { Form: { compo: 'Form', state: { type: 'student', }, props: { name: 'basic', initialValues: { remember: true }, onFinish: "(values) => { console.log('Success:', values); }", onFinishFailed: "(errorInfo) => { console.log('Failed:', errorInfo); }", onValuesChange: '(changedFields, allFields) => { console.log(changedFields); console.log(this.state); if (changedFields.type){ this.setState({type:changedFields.type}); this.formRef.current.setFieldsValue({grade:""})} }', onFieldsChange: '(changedFields, allFields) => { console.log("onFieldsChange Params:",changedFields, allFields); console.log("onFieldsChange"); }', labelCol: { span: 8, }, wrapperCol: { span: 16, }, }, child: { } } } ``` **Main Aim** - The **json** variable will be modified everytime by the user that will cause the re-render to happen everytime. - for example: - Upon placing a new form component, the component's json will be added to **json** variable. - When a new component is placed or any component is selected, the Accessibilty Menu will show the Props of that component and that props can be changed by the user from that Accessibility Menu UI. When any change is made from the Accessibilty menu, the json is again modified, thus causing a re-render. **Selecting a form component** ```js // get all form components let formItems = document.querySelectorAll('.ant-form-item'); // search and get that clicked form component formItems.forEach(formItem => { formItem.addEventListener('click', (event)=>{ let selectedNode = event.target while(selectedNode !== formItem){ selectedNode = selectedNode.parentNode } if(formItem === selectedNode){ let index = Array.from(formItems).indexOf(formItem) console.log('index of selected component: ', index + 1); } }) }) ``` **Adding/Deleting/Modifying a form components** - In FormBuilder.jsx, there will be two different functions to add and delete a form component. - Adding a component - When a component is placed/added, assigning the key of this form component is the main priority. The key is basically looks like "Item1", "Item2", etc - in the name "Item1", "1" is the index. - when this child components is added to the form at a specific position, say, the fourth position from the top, then, its key's name must be Item4. - All the existing key with index <= 4 :- "Item4", "Item5", "Item6", so on... will have a increment of 1 in thier index - Item4 -> Item5, Item5 -> Item6, Item6-> Item7 and then, the new Item4 is appended in the JSON's child object. - JSON is always sorted wrt keys of the children key-value pairs. So, Item4 will always be present in the 4 position of the child object in the JSON. - Deleting a component - When a component is removed/deleted, the JSON for that deleted child component is removed and the indexes of the components that have greater index value will have a decrement of 1 in their index - Lets say the form component at 4th position fro top is to be removed, - The Item4 is discarded from the child object in the JSON. - existing keys with index > 4 will have a decrement in their indexes. i.e., Item5 -> Item4, Item6 -> Item5, Item7-> Item6 - Modifying a component's props. - Using the Accessibily menu, the props of the selected component can be modified ## FormComponentsMenu.jsx It will contain all form Components that can be drag dropped to the middle-area ## AccessibilityMenu.jsx To generate the modifiers or Knobs UI, the **props object** will be rendered in a specific meainingful way for example consider the props object:- ``` props: { id: this, label: 'Username', name: 'username', rules: [ { required: true, message: 'Please input your username!', }, ], } ``` here, the Knobs UI for the direct childrem of props object will be rendered in a different way And the Knobs UI for the rules Array will be rendered in a different way ---------------------------------- ## Test Cases 1. Placing an form Component. - Simply drag and drop a form component from component sidebar to the middle area 2. Removing a form Component. - Hover on the form component and when the delete icon appears on the component, click on that icon to delete component 3. Repositioning a form Component. - Drag and shift the component upwards or downwards to reposition it 4. Modifying the component's props. - click on a placed form component. on the right hand side accessibility menu modify the props to change the component's props.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully