A Pen by Akın Özgen on CodePen.
Last active
January 17, 2019 18:57
-
-
Save akinozgen/4aabadd0ec08142b8ce75e2b80e27b48 to your computer and use it in GitHub Desktop.
jamaljs character counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="app"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* http://jamal.js.org | |
* Akın Özgen <akinozgen17@outlook.com> | |
* Latest Version: https://unpkg.com/jamal@latest/build/src.min.js | |
*/ | |
const _ = Jml; | |
_.initialize(); | |
const context = _.form( | |
{ class: 'container', style: 'margin-top: 50px' }, | |
_.div({ class: 'form-group' }, [ | |
_.label({ for: 'about' }, ['About You ', _.small('Maximum 50 characters')]), | |
_.textarea({ | |
class: 'form-control', | |
target: '#counter', | |
id: 'about', | |
_onInput: function () { | |
const el = document.querySelector( this.attributes['target'].value ); | |
el.innerText = this.value.length; | |
if (this.value.length > 50) { | |
el.style.color = 'red'; | |
el.style.fontWeight = 'bold'; | |
} else { | |
el.style.color = 'inherit'; | |
el.style.fontWeight = 'inherit'; | |
} | |
} | |
}), | |
_.small(['You entered ', _.span({ id: 'counter' }, '0'), ' characters.']) | |
]) | |
); | |
const app = _.create('#app', context); | |
app.render(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://unpkg.com/jamal@latest/build/src.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment