Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"Label inside input via title property" for Opa
/***************************************
* 2nd day of playing around with Opa.
* 1st somewhat useful bit of code.
* Probably a better way to write this,
* but definitely don't want to reinvent
* this later. Would like to have this to
* build off of!
*
* Hope it helps you.
****************************************/
start() = (
<input id=#some_prompt class="xlarge" title="Enter something here!" onready={prompt_blurred(#some_prompt, _)} onfocus={prompt_focused(#some_prompt, _)} onblur={prompt_blurred(#some_prompt, _)} />
)
prompt_focused(element, _) =
(
prompt = Dom.get_property_unsafe(element, "title")
do if String.equals(Dom.get_value(element), prompt) then
Dom.set_value(element, "")
void
)
prompt_blurred(element, _) =
(
do if String.equals(String.strip(Dom.get_value(element)), "") then
Dom.set_value(element, Dom.get_property_unsafe(element, "title"))
void
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.