Is there a way to allow bootstrap 4 designed web pages (as Nitrogen templates) to "interact" with Erlang Nitrogen?
Apart from breaking out all input fields, buttons and forms and converting it to Nitrogen, is it possible to leave the designed HTML pages intact and add tags to tell nitrogen to do the postback event on a button when rendering, or access the content of a field?
This is the designed bootstrap code for instance, and I would like to have the postback be handled by Nitrogen. (All the required javascript and css is included in the page, and the web page is the template of the Nitrogen module called).
<form class="form-horizontal m-t-20 " id="loginform" name="loginform" method="POST" action="#">
<div class="input-group mb-3 ">
<div class="input-group-prepend ">
<span class="input-group-text " id="basic-addon1 "><i class="ti-user "></i></span>
</div>
<input type="text " class="form-control form-control-lg " placeholder="Username " aria-label="Username " aria-describedby="basic-addon1 " id="login_username">
</div>
<div class="form-group text-center ">
<div class="col-xs-12 p-b-20 ">
<button class="btn btn-block btn-lg btn-info " type="submit" postback=login>Log In</button>
</div>
</div>
This is an interesting idea. It's possible to achieve this with minimal changes.
Using your original code, any form elements that you want to be captured in a postback would have to have to the class
wfid_ELEMENT_ID.For example:
(note
wfid_login_usernamein the class).Also, the
<form>element will be outright ignored by Nitrogen (at current, anyway), so it can safely be removed.Then to do the postback, you have two options:
The traditional way in Nitrogen:
wf:wire(button_id, #event{type=click, postback=login}), orUse the #api action, with some javascript which should allow you to get away with using a
postbackHTML attribute:First, wire the #api action (API Docs: https://nitrogenproject.com/doc/action_api.md)
Then, use javascript to scan the DOM for
postback=SOMETHINGand wire the relatedpage.myapicall.Finally, build the handler function for your api:
Of course, by doing this, you lose a lot of the capabilities of postbacks, since the postback can safely wrap up complex terms like tuples, maps, etc - this method would literally postback just the string attached to the
postbackHTML attribute. But it should work for simple interfaces like this.