Skip to content

Commit

Permalink
Added type, min and max attributes to input view (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
exdis authored and lahmatiy committed Mar 7, 2019
1 parent 562353a commit 814e296
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion client/views/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ export default function(discovery) {
};

discovery.view.define('input', function(el, config, data, context) {
const { name, value, type = 'text', placeholder, onInit, onChange } = config;
const { name, value, type = 'text', placeholder, onInit, onChange, htmlType = 'text', htmlMin, htmlMax } = config;
const factory = factories[type] || factories.text;
const inputEl = el.appendChild(document.createElement('input'));
let lastInput = defined([value, context[name]], '');

inputEl.type = htmlType;
inputEl.value = lastInput;
inputEl.placeholder = [
placeholder || '',
factory !== factories.text ? '(' + type + ')' : ''
].filter(Boolean).join(' ');

if (typeof htmlMin !== 'undefined') {
inputEl.min = htmlMin;
}

if (htmlMax) {
inputEl.max = htmlMax;
}

inputEl.addEventListener('input', () => {
const newInput = inputEl.value.trim();

Expand Down

0 comments on commit 814e296

Please sign in to comment.