|
| 1 | +## April 26 ([discuss](https://github.com/SimplrJS/simplr-forms/pull/26)) |
| 2 | + |
| 3 | +### Attendees |
| 4 | + |
| 5 | +* [Dovydas](https://twitter.com/dovydasnav) (QuatroDev) |
| 6 | +* [Martynas](https://twitter.com/MartiogalaLT) (QuatroDev) |
| 7 | + |
| 8 | +### State of mind |
| 9 | + |
| 10 | +:tada: :clap: :tada: :clap: :tada: :clap: :tada: :clap: :tada: :clap: :tada: :clap: |
| 11 | + |
| 12 | +### Sooooo... What happened? |
| 13 | + |
| 14 | +After quite a bit of work, a first e2e workflow now forks. Non-test, but a working browser example! |
| 15 | + |
| 16 | +### So... How does it look? |
| 17 | + |
| 18 | +Technical. No styles, no nothing, just two text fields and a form. And you can submit the form (this one is big for the library :smile:). |
| 19 | + |
| 20 | +### And if we spoke code? |
| 21 | + |
| 22 | +Right. So the exciting part is that everything works as planned: |
| 23 | + |
| 24 | +A declarative and intuitive way to build forms. |
| 25 | + |
| 26 | +The whole react application including the form looks like this: |
| 27 | +```ts |
| 28 | +import * as React from "react"; |
| 29 | +import * as ReactDOM from "react-dom"; |
| 30 | +import "tslib"; |
| 31 | +import { FormStore } from "simplr-forms-core/stores"; |
| 32 | +import { Form, Text, Submit } from "simplr-forms-dom"; |
| 33 | + |
| 34 | +export class MyForm extends React.Component<{}, { formId: string }> { |
| 35 | + protected onSubmit: any = (event: React.FormEvent<HTMLFormElement>, store: FormStore) => { |
| 36 | + console.log("Submitting..."); |
| 37 | + console.log(store.ToObject()); |
| 38 | + }; |
| 39 | + |
| 40 | + render() { |
| 41 | + return <Form onSubmit={this.onSubmit}> |
| 42 | + <label> |
| 43 | + Full name: |
| 44 | + <Text name="FullName" /> |
| 45 | + </label> |
| 46 | + <label> |
| 47 | + Email: |
| 48 | + <Text name="Email" /> |
| 49 | + </label> |
| 50 | + <Submit>Submit</Submit> |
| 51 | + </Form>; |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +ReactDOM.render(<MyForm />, document.getElementById("react-root")); |
| 56 | +``` |
| 57 | +
|
| 58 | +When rendered, it's a plain form: |
| 59 | +
|
| 60 | + |
| 61 | +
|
| 62 | +And even html rendered is as plain as it can be: |
| 63 | +
|
| 64 | + |
| 65 | +
|
| 66 | +It's not "like" a `plain HTML form`. It IS a plain HTML form. |
| 67 | +
|
| 68 | +But when filled and submitted, it prints this into console: |
| 69 | +
|
| 70 | + |
| 71 | +
|
| 72 | +Can you see it already? :smile: |
| 73 | +
|
| 74 | +Declarative form with an intuitive, almost default `onSubmit`, where getting an object of the whole form boils down to this: |
| 75 | +```ts |
| 76 | +store.ToObject() |
| 77 | +``` |
| 78 | +
|
| 79 | +The only difference from the "default" `onSubmit` is that you get `FormStore` as a second parameter into the handler. And that is only for your convenience. You can take it in a few different ways, if you want. |
| 80 | +
|
| 81 | +And what `FormStore` gives you is simplicity. The `ToObject()` method takes care of knowing how to transform data in the store into a plain object. You don't have to take care of any refs, values, nothing. Name your fields with.. Well, `name`. And you're good to go! |
| 82 | +
|
| 83 | +Easy? Super easy! |
| 84 | +
|
| 85 | +### That's amazing? But... Where's everything else? |
| 86 | +
|
| 87 | +This simple example shows what works e2e at this very monent, but even here, quite a lot of things are handled behind the scenes: |
| 88 | +* Form is registered with `FormStoresHandler` and `FormStore` is initiated. |
| 89 | +* `formId` is not given, therefore it is generated automatically for you. |
| 90 | +* Both `text` fields are registered with the same store with the same generated `formId` and you didn't have to do anything! |
| 91 | +* `Submit` button used here is from `simplr-forms-dom`, but no custom logic is being used in this example. It's basically your default `<button type="submit">Submit</button>` and it could be one. Because effectively this one is, as you can see in the HTML shown above :+1: No custom click handlers, nothing. Plain button of type `submit`. |
| 92 | +* Everything behind the scenes updates data in the `FormStore` for you and you can already listen to actions coming from `FormStore` and do what you need accordingly. |
| 93 | +
|
| 94 | +Also, I'm pretty sure `Modifiers` and `Normalizers` would work already, but did not test that yet. |
| 95 | +`Validators` with `simplr-validation` package also do what they are supposed to do (kudos to [Martynas](https://twitter.com/MartiogalaLT) for that one). |
| 96 | +
|
| 97 | +Oh, riiight. Since the last post almost two weeks ago, [Martynas](https://twitter.com/MartiogalaLT) has already finished an initial version of `simplr-validation` and we will test it out soon and make the forms ready for it. |
| 98 | +
|
| 99 | +### So the validation is tightly coupled with forms and not externalized... |
| 100 | +
|
| 101 | +No! Well, yes, but no! :smile: |
| 102 | +
|
| 103 | +It is coupled only by a public API that `simplr-forms-core` exposes and that's it. |
| 104 | +
|
| 105 | +You already can create your own validation library and just use the same public API and you're good to go! |
| 106 | +
|
| 107 | +Why am I so sure? Because, `simplr-validation` does just that. |
| 108 | +
|
| 109 | +### Awesome. What's next? |
| 110 | +
|
| 111 | +Until we can ship a solid alpha, we need to have: |
| 112 | +* Most commonly used HTML components covered in `simplr-forms-dom`. |
| 113 | +* Modifiers and Normalizers working. |
| 114 | +* Validation working with `simplr-forms-dom`. |
| 115 | +
|
| 116 | +Until we can ship a solid beta, we need to have: |
| 117 | +* All HTML components covered in `simplr-forms-dom`. |
| 118 | +* Reliably working `FieldsGroup`. |
| 119 | +
|
| 120 | +As soon as we have something solid, we will ask a few people to test it out. And for the mean time, yay for a first e2e flow! |
| 121 | +
|
| 122 | +------------ |
| 123 | +
|
| 124 | +The feedback and questions are more than welcome! |
| 125 | +
|
| 126 | +------------ |
| 127 | +
|
| 128 | +Please feel free to discuss these notes in the [corresponding pull request](https://github.com/SimplrJS/simplr-forms/pull/26). |
0 commit comments