dealing with selects, checkboxes and radio buttons

36 views
Skip to first unread message

Chris Jeffries

unread,
Jul 8, 2018, 10:48:28 AM7/8/18
to JavaScript Templates Engine PURE
I wanted to be able to retrieve data in its natural form and use it on the page without massaging - which seemed an inevitability for setting the correct element seleceted ina select or checked in input checkbox/radio, so I dug into the pure.js file and made a mod so that you can set a value attribute on a select tag and it will automatically mark the correct option as selected.

I also wrote a function to allow a similar behaviour for input checkboxes and radio buttons. But this is an independent function that addresses this issue after the page has been built via the DOM. Basically, I would have had to write a parser, and the DOM was sitting there already parsed begging me to use it. Being a separate function has the advantage that you need not incur the overhead if you don't have checkboxes or radio buttons, whose values you want to set, on the page.

I would like to make sure these introduce no regression errors, so, my question: Is there a test suite for the code so I can make sure I didn't zap anything else?


Mic (BeeBole)

unread,
Jul 8, 2018, 12:32:01 PM7/8/18
to JavaScript Templates Engine PURE
Hi Chris,

First. I'm sorry for the delay in answering your other questions.

pure.js is still the workhorse that renders our SaaS application today.
But simple rendering engines have lost the favour of developers for more comprehensive framework like angular, react, etc.
As we found pure.js had all it needed to generate HTML from a template and a JSON, we didn't invest anymore time in finding new features for a long time.
We just use it as it is. Fixing bugs as new browser versions get out if needed.

But I'm all for improving it if it is a generic HTML feature.
Just to understand, why the @selected and @checked didn't cover your needs ?
Do not hesitate to make a pull request on github or send your code change here.

Thank you for using pure.js !

Cheers,
-Mic
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Chris Jeffries

unread,
Jul 9, 2018, 1:36:44 AM7/9/18
to JavaScript Templates Engine PURE
Here's the a diff. There are comments in the file.

As for why these? They allow you to put in the JSON data going from server to client basically the same as you would get when the form is submitted back up to the server, without having to fiddle around working out which option or input element to set the selected or checked attribute on.

It is currently incomplete as it does not allow for multiple values in the case of select multiple and checkboxes. If I find a need for those I will extend.
diffs
Reply all
Reply to author
Forward
Message has been deleted
0 new messages