Fork me on GitHub
#hoplon
<
2016-04-18
>
thedavidmeister11:04:32

hey, what would be a good way to validate/coerce/enforce constraints on data going into datascript

thedavidmeister11:04:13

like, i want some attribute to always be a float, for example

dm311:04:18

ideally you'd have functions a level higher than transact! validating the inputs. Otherwise you can have your own transact! which takes a schema (or is called with an implicit schema) that the validations are run against.

thedavidmeister11:04:17

so why would you suggest something higher level than a custom transact!?

thedavidmeister11:04:52

maybe i need a defmulti...

dm311:04:15

well, it depends on where you want your validation logic

dm311:04:30

if you're ok on having static validation in database schema

dm311:04:41

then custom transact! is good

thedavidmeister13:04:12

so i have something that looks loosely like this

thedavidmeister13:04:25

(defc foo "")

(input
  :value foo
  :input (if-let [n (parse-number @%)] (reset! foo n)))

thedavidmeister13:04:13

i’m trying to stop values i don’t like

thedavidmeister13:04:31

but if someone writes 42a

thedavidmeister13:04:59

foo is not reset, so :value does not update

dm313:04:20

it's usually a good rule not to mess with what user inputs

dm313:04:29

highly frustrating

thedavidmeister13:04:44

you don’t even know what i’m doing...

thedavidmeister13:04:59

only numbers are OK for this input

dm313:04:08

only judge by the example simple_smile

thedavidmeister13:04:30

well i want to accept numbers in the field but not letters

thedavidmeister13:04:57

if i get it working, i’ll add errors and stuff to make it obvious what is going on

dm313:04:06

my suggestion still stands 😉 but doesn't it work that way already?

thedavidmeister13:04:09

starting with the basics

thedavidmeister13:04:31

no, it doesn’t work that way

thedavidmeister13:04:42

:value only does something if the cell changes

dm313:04:08

personally I strongly dislike inputs that do not show what I typed in

thedavidmeister13:04:02

kind of irrelevant

dm313:04:30

in this case it seems you have to have two cells

dm313:04:57

oh, it seems that I've not understood you from the start, sorry simple_smile

dm313:04:22

do you actually want to show whatever user inputs, but only store the valid input in the cell?

thedavidmeister13:04:09

i only want to store valid input

thedavidmeister13:04:49

but if you don’t store it, it will just disappear on page refresh

thedavidmeister13:04:00

it will silently die

dm313:04:29

then you have 'user input'/'user input error'/'valid parsed value' pieces of data

dm313:04:13

that you need to store

thedavidmeister13:04:04

hangong, i’m going to restart slack

thedavidmeister13:04:29

(defc foo "")
(defc foo-raw "")

(input
  :value foo
  :data-error (cell= (= foo foo-raw)
  :input (do  (if-let [n (parse-number @%)] (reset! foo n))
              (reset! foo-raw @%)))

dm313:04:43

:value foo-raw, no?

thedavidmeister13:04:47

i mean, it doesn’t matter

thedavidmeister13:04:51

it’s beside the point

thedavidmeister13:04:25

because the user can write whatever they want in the field and :value gets stale the moment something doesn’t validate

thedavidmeister13:04:51

it’s either not representing what is actually being used for calculations elsewhere, because it’s not showing the valid bit

thedavidmeister13:04:29

or it is showing what will be used for calculations when you load up the page, but you might lose some (invalid) input

dm313:04:46

yeah, storing invalid input is too much I think

thedavidmeister13:04:19

i’m using cells to make the app more responsive, no need to submit forms and wait for a page refresh

thedavidmeister13:04:45

but now i’m not sure what to do, show calculations that don’t line up with input, or restrict input, or… something else??

dm313:04:59

that's what I was trying to suggest simple_smile

dm313:04:08

part of the answer to that question

dm313:04:24

UX rule #1: don't mess with user input

thedavidmeister13:04:56

but it’s just not possible

dm313:04:00

which means showing whatever user typed in, highlighting errors and running calculations only when the error is cleared

thedavidmeister13:04:40

spreadsheets don’t do that (for example)

dm313:04:40

you can have an action appear beside the error to "sanitize input"

dm313:04:53

spreadsheets propagate #ERROR

dm313:04:00

so you can do that too

dm313:04:08

dependening on who is your user

dm313:04:13

one model might be better than the other

dm313:04:22

(e.g. if your users are heavy spreadsheet users, spreadsheet model makes more sense)

thedavidmeister13:04:46

that’s a good question

thedavidmeister13:04:24

i think i need to sleep on this

thedavidmeister13:04:31

:value is giving me so much grief, lol

onetom15:04:36

@jumblerg: wow, i was extending the clj castra writer to convert joda-time to instant just last week!

jumblerg16:04:52

@onetom: good to know i’m not the only one. you can use it as follows:

(defn remote [endpoint & [opts]]
  (let [opts* {:url url :on-error #(when dev (println  %)) :reader-opts {:handlers {"r" identity}}}]
    (c/mkremote endpoint q/session q/error q/loading (merge opts* opts))))

raywillig17:04:38

hi anyone know where the hoplon jquery-selectize repo ended up?

jumblerg17:04:19

unless you’re looking for a hoplon specific version

raywillig17:04:19

@jumblerg: thx that’s just the ext file. i grabbed the jar from clojars. I just needed to look at the source

raywillig17:04:57

yeah, there’s a hoplon defelem that @alandipert or @micha whipped up a while back

micha17:04:41

@raywillig: you can view the files in the jar with vi or emacs, i think both know how to do that out of the box

raywillig17:04:52

wow, didn’t know that. very coo

alandipert18:04:40

in emacs at least you can edit jars in place also, which is handy/dangerous

alandipert18:04:45

but i do it on the reg

micha18:04:55

handgerous

jouerose22:04:50

hi all, is there a special hoplon form for websocket