discourse/app/assets/javascripts/admin/addon/components/modal
chapoi 2ca06ba236
DEV: form-kit
This PR introduces FormKit, a component-based form library designed to simplify form creation and management. This library provides a single `Form` component, various field components, controls, validation mechanisms, and customization options. Additionally, it includes helpers to facilitate testing and writing specifications for forms.

1. **Form Component**:
   - The main component that encapsulates form logic and structure.
   - Yields various utilities like `Field`, `Submit`, `Alert`, etc.

   **Example Usage**:
   ```gjs
   import Form from "discourse/form";

   <template>
     <Form as |form|>
       <form.Field
         @name="username"
         @title="Username"
         @validation="required"
         as |field|
       >
         <field.Input />
       </form.Field>

       <form.Field @name="age" @title="Age" as |field|>
         <field.Input @type="number" />
       </form.Field>

       <form.Submit />
     </Form>
   </template>
   ```

2. **Validation**:
   - Built-in validation rules such as `required`, `number`, `length`, and `url`.
   - Custom validation callbacks for more complex validation logic.

   **Example Usage**:
   ```javascript
   validateUsername(name, value, data, { addError }) {
     if (data.bar / 2 === value) {
       addError(name, "That's not how maths work.");
     }
   }
   ```

   ```hbs
   <form.Field @name="username" @validate={{this.validateUsername}} />
   ```

3. **Customization**:
   - Plugin outlets for extending form functionality.
   - Styling capabilities through propagated attributes.
   - Custom controls with properties provided by `form` and `field`.

   **Example Usage**:
   ```hbs
   <Form class="my-form" as |form|>
     <form.Field class="my-field" as |field|>
       <MyCustomControl id={{field.id}} @onChange={{field.set}} />
     </form.Field>
   </Form>
   ```

4. **Helpers for Testing**:
   - Test assertions for form and field validation.

   **Example usage**:
   ```javascript
   assert.form().hasErrors("the form shows errors");
   assert.form().field("foo").hasValue("bar", "user has set the value");
   ```

   - Helper for interacting with he form

   **Example usage**:
   ```javascript
   await formKit().field("foo").fillIn("bar");
   ```

5. **Page Object for System Specs**:
   - Page objects for interacting with forms in system specs.
   - Methods for submitting forms, checking alerts, and interacting with fields.

   **Example Usage**:
   ```ruby
   form = PageObjects::Components::FormKit.new(".my-form")
   form.submit
   expect(form).to have_an_alert("message")
   ```

   **Field Interactions**:
   ```ruby
   field = form.field("foo")
   expect(field).to have_value("bar")
   field.fill_in("bar")
   ```


6. **Collections handling**:
   - A specific component to handle array of objects

   **Example Usage**:
   ```gjs
    <Form @data={{hash foo=(array (hash bar=1) (hash bar=2))}} as |form|>
      <form.Collection @name="foo" as |collection|>
        <collection.Field @name="bar" @title="Bar" as |field|>
          <field.Input />
        </collection.Field>
      </form.Collection>
    </Form>
   ```
2024-07-17 11:59:35 +02:00
..
api-key-urls.hbs DEV: Convert api-key-urls modal to component-based API (#22913) 2023-08-01 14:51:18 -05:00
badge-preview.hbs FIX: Badge preview not displaying grant count (#23269) 2023-08-25 09:19:01 -05:00
badge-preview.js DEV: form-kit 2024-07-17 11:59:35 +02:00
color-scheme-select-base.hbs DEV: Use fn+mut instead of action+mut (#26057) 2024-03-06 18:05:03 +01:00
color-scheme-select-base.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
custom-date-range.hbs FEATURE: add custom date range filter for admin dashboard reports (#23702) 2023-09-29 14:44:17 +05:30
custom-date-range.js DEV: Sort imports 2023-10-10 21:46:54 +01:00
delete-posts-confirmation.hbs
delete-posts-confirmation.js DEV: Rename I18n imports to discourse-i18n (#23915) 2023-10-18 11:07:09 +01:00
delete-user-posts-progress.hbs DEV: Convert delete-user-posts-progress modal to component-based API (#22916) 2023-08-01 15:49:26 -05:00
delete-user-posts-progress.js DEV: Rename I18n imports to discourse-i18n (#23915) 2023-10-18 11:07:09 +01:00
edit-badge-groupings.hbs DEV: Convert edit-badge-groupings modal to component-based API (#22984) 2023-08-14 12:03:28 -05:00
edit-badge-groupings.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
form-template-validation-options.hbs DEV: Convert form-template-validation-options modal to component-based API (#23236) 2023-08-25 07:02:54 -05:00
form-template-validation-options.js DEV: Rename I18n imports to discourse-i18n (#23915) 2023-10-18 11:07:09 +01:00
incoming-email.hbs
install-theme.hbs DEV: Add loading spinner to install theme modal (#25888) 2024-02-26 14:14:21 -07:00
install-theme.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
merge-users-confirmation.hbs DEV: Convert merge-users modals to component-based API (#22727) 2023-08-01 10:35:36 -05:00
merge-users-confirmation.js DEV: Rename I18n imports to discourse-i18n (#23915) 2023-10-18 11:07:09 +01:00
merge-users-progress.hbs DEV: Convert merge-users modals to component-based API (#22727) 2023-08-01 10:35:36 -05:00
merge-users-progress.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
merge-users-prompt.hbs DEV: Fix array-related linting issues in templates (#22935) 2023-08-02 19:43:37 +02:00
merge-users-prompt.js DEV: Convert merge-users modals to component-based API (#22727) 2023-08-01 10:35:36 -05:00
penalize-user.hbs DEV: Use fn+mut instead of action+mut (#26057) 2024-03-06 18:05:03 +01:00
penalize-user.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
reseed.hbs DEV: Convert reseed modal to component-based API (#23232) 2023-08-25 07:21:38 -05:00
reseed.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
site-setting-default-categories.hbs DEV: Convert site-setting-default-categories modal to component-based API (#22968) 2023-08-10 10:31:34 +01:00
site-setting-default-categories.js DEV: Convert site-setting-default-categories modal to component-based API (#22968) 2023-08-10 10:31:34 +01:00
staff-action-log-details.hbs DEV: Convert staff-action-log-details modal to component-based API (#23240) 2023-08-25 06:43:52 -05:00
start-backup.hbs FIX: Add checkbox-label to more checkbox label elements (#24174) 2023-10-31 08:57:50 +01:00
start-backup.js DEV: Use the "new" service import (#26059) 2024-03-06 18:05:11 +01:00
theme-change.hbs DEV: Convert theme-change modal to component-based API (#22964) 2023-08-03 15:01:40 -05:00
theme-change.js DEV: Convert theme-change modal to component-based API (#22964) 2023-08-03 15:01:40 -05:00
uploaded-image-list.hbs FIX: Allow deleting avatars from the selectable avatars setting (#26720) 2024-04-24 16:07:12 -04:00
uploaded-image-list.js FIX: Allow deleting avatars from the selectable avatars setting (#26720) 2024-04-24 16:07:12 -04:00
watched-word-test.hbs DEV: Convert watched-word-test modal to component-based API (#22911) 2023-08-01 16:08:56 -05:00
watched-word-test.js PERF: Avoid excessive object creations in watched words (#27354) 2024-06-10 14:44:31 +02:00