Welcome the channel on the development of Cro, a set of libraries for building reactive distributed systems, lovingly crafted to take advantage of all the Raku Programming Language has to offer (cro.services). This channel is being logged for historical purposes. Set by lizmat on 24 May 2021. |
|||
00:07
Pe_Elle joined
00:11
Pe_Elle left
00:41
Pe_Elle joined
|
|||
SmokeMachine | I tried figuring out a way to add htmx (and/or custom) attributes on Cro::WebApp::Form (like hx-post for example), but I couldn’t find a way. Is there a way? If not, is that ok if I create a PR adding a $!form-custom-attributes attribute to make it possible? | 02:31 | |
I meant %!form-custom-attributes | 02:35 | ||
03:06
Pe_Elle left
03:07
Pe_Elle joined
03:57
Pe_Elle left
04:02
Pe_Elle joined
04:06
Pe_Elle left
04:30
Pe_Elle joined
04:34
Pe_Elle left
06:01
Pe_Elle joined
07:59
lizmat left
08:32
Pe_Elle left
08:43
Pe_Elle joined
09:09
sena_kun joined
10:10
Pe_Elle left
10:11
Pe_Elle joined
11:06
Pe_Elle left,
Pe_Elle joined
11:16
Pe_Elle left
11:33
Pe_Elle joined
11:46
sena_kun left
11:47
sena_kun joined
11:52
sena_kun left
11:53
sena_kun joined
11:56
sena_kun left
11:57
sena_kun joined
12:16
sena_kun left
12:17
sena_kun joined
12:36
Pe_Elle left
13:02
Pe_Elle joined
13:07
Pe_Elle left
13:35
jnthn1 joined,
Pe_Elle joined
13:40
jnthn left
14:40
Pe_Elle left
14:55
Pe_Elle joined
15:12
Pe_Elle left
15:31
sena_kun left
15:40
Pe_Elle joined
15:43
Pe_Elle left,
Pe_Elle joined
15:44
Pe_Elle left
15:46
Pe_Elle joined
15:48
sena_kun joined
15:51
Pe_Elle left
16:05
sena_kun left
|
|||
SmokeMachine | does that make sense ☝️? | 16:06 | |
16:17
Pe_Elle joined
16:21
Pe_Elle left
16:35
Pe_Elle joined
|
|||
librasteve | SmokeMachine: Yep - that makes perfect sense and would also be great for my needs. but I would like it to go further in that each input should be able to have custom (hx-) attrs ... maybe for example for dipping in a Red model to check availability of a desired username. This is a bit tricky since I guess it would need to be per input not per input type. | 16:50 | |
I note that when I go TestForm.empty.HTML-RENDER-DATA I get a prepared Cro template data sturcture that is then consumed by prelude.crotmp. My idea for Air is to consume the same data structure within an Air::Function class to make HTML. So I would request that anything you make respect this intermediate form slang and I can port over the prelude.crotmp changes. | 16:53 | ||
So having said that makes me wonder best way to specify the hx-attrs in my form class... | 16:54 | ||
What do you think about some thing like this: | 16:55 | ||
role HxForm { method hx-tags(--> Hash()) { :hx-get("$.url-id/toggle"), :hx-target<closest tr>, :hx-swap<outerHTML>, } } } class BlogPost does Cro::WebApp::Form does HxForm { has Str $.title is required; has Str $.content is multiline; has Str $.category will select { 'Coding', 'Photography', 'Trains' }; has Str @.tags is attributed { |self.hx-tags } will select { | 16:59 | ||
'Raku', 'Compiler', 'Landscape', 'City', 'Steam' } } | |||
SmokeMachine | librasteve: for the field validation, isn’t enough something like: `has &.nick is validated({ !User.^all.first: *.name eq $_ }, “Username already used”);` ? | ||
librasteve | SmokeMachine: good point - sorry I was just trying to come up with an example - maybe my idea is overkill | 17:00 | |
SmokeMachine | I am planing on changing the form sub template itself and make it accept something like: `<$form(.form, :form-custom-attributes{ hx-post => $url })>` | 17:01 | |
librasteve | yeah - I think that's fine, at the <form hx-get...>...</form> level | 17:03 | |
SmokeMachine | I don’t think it should be defined on the Form class… the Form could be used on different parts of the page with different hx-… values on each of them… | ||
librasteve | I havent done any real messing with Cro forms yet and so I am currently vague what may be needed at the individual input level - my guiding star is to imagine all the HTMX examples somehow in a form, here's a typical one htmx.org/examples/bulk-update/ | 17:07 | |
but this example would work with your solution | 17:08 | ||
let me check the other examples | |||
ok I did site:htmx.org/examples/ form | 17:11 | ||
SmokeMachine | And I’m thinking if it should be better to use a red model as a form (on the same class we define the red model and probably define the Cromponent (example: github.com/FCO/Discuss/blob/main/l...c.rakumod) or if I should make it easy to create a record from a from, or none… I say that, because on this example: github.com/FCO/Discuss/blob/a8e27f...kumod#L20, the form | ||
being a model would not help… and it would just be easier to just do: `$.messages.create: body => $form.body, code => $form.code, author => %( nick => $form.nick )` | |||
librasteve | there are 3 HTMX examples involving form where children of the form element also need HTMX (or JS), these are: | ||
htmx.org/examples/inline-validation/ | 17:12 | ||
htmx.org/examples/file-upload-input/ | |||
htmx.org/examples/file-upload/ | |||
The first one (as you mention) should be handled by the Cro::WebApp::Form is validated trait - I guess that there is a small possibility that the raku validation will not dance with the HTMX - I suggest to try your solution first and see how is works | 17:14 | ||
SmokeMachine | In this 1st example, I think that div with the email address would just be a component, right? | 17:15 | |
librasteve | The other two are file upload specific and I think that when we get to multipart file upload maybe we will need to do something a bit more custom for eg progress bars - again I think we should stat with your solution and solve this later | ||
BTW I have implemented all these examples already with Cro Template (not Cro Forms though) at github.com/librasteve/raku-HTMX-Examples | 17:17 | ||
SmokeMachine | Because that validation is not being done on submit, but on change… it will not get the form data (only the email)… then I don’t think form could help there… | 17:19 | |
librasteve | Well, maybe the email div is a component - but it is also an input - I am not sure how these two things can be combined tbh ... have you any thoughts on that? | ||
SmokeMachine | On submit the email will also be sent… then form could help… the email would be validated twice on 2 different places… :( | 17:20 | |
librasteve | I am 100% in agreement that a model is a Cromponent is a Form (with mixing traits on the has declarations) would be awesome (as in your Topic code) | 17:21 | |
SmokeMachine | Maybe we could extend form to validate each field when called… | ||
I’m not sure about red being a form yet… :( | 17:23 | ||
librasteve | sorry maybe I did not explain well - I am looking at your topic code and thinking of | 17:27 | |
model Message does Cromponent Cro::WebApp::Form is table { has Str $.body is column is multiline; ... method RENDER-FORM-DATA { # form HTML you use within the Topic.RENDER as .form } } | 17:31 | ||
^^ this is just a wild idea right now (well I guess you would use it as the data to prime the form Cro template | 17:32 | ||
sorry must finish $day-job ... please do go ahead and make PR the way you think is best, I can help to review it then... | 17:33 | ||
17:36
Pe_Elle left
18:01
Pe_Elle joined
18:06
Pe_Elle left
18:12
lizmat joined
18:29
lizmat left
18:34
Pe_Elle joined
18:39
Pe_Elle left
19:26
Pe_Elle joined
19:31
Pe_Elle left
19:41
Pe_Elle joined
19:49
Pe_Elle left
20:03
Pe_Elle joined
21:06
Pe_Elle left
21:34
Pe_Elle joined
21:43
Pe_Elle left
22:01
guifa joined,
Pe_Elle joined
22:17
lizmat joined
22:53
lizmat_ joined
22:56
lizmat left
23:04
Pe_Elle left
23:34
Pe_Elle joined
23:36
lizmat_ left
23:39
Pe_Elle left
23:40
Pe_Elle joined
23:44
Pe_Elle left
|