Skip to content

Instantly share code, notes, and snippets.

@colwem
Created March 19, 2016 20:27
Show Gist options
  • Select an option

  • Save colwem/ec521089c4c97a6d039a to your computer and use it in GitHub Desktop.

Select an option

Save colwem/ec521089c4c97a6d039a to your computer and use it in GitHub Desktop.
'use strict';
riot.tag2('cron-time', ' <select onchange="{_update}">\n <option each="{hours}" value="{hour}" __selected="{selected}">{hour}</option>\n </select>\n', '', '', function(opts) {
const self = this;
function range(start, end) {
return Array.apply(Array, Array(1 + end - start)).map((_, i) => {
return i + start;
});
}
this.hours = range(opts.dayStart + 1, 24).map((hour) => {
return {
hour: hour,
selected: opts.cronTime === hour ? true : false
};
});
let url = '/users/update';
this._update = function(e) {
$.post(url,
{
cronTime: e.target.value
},
(data, status) => {
console.log(data);
console.log(status);
}
);
}.bind(this)
});
'use strict';
cron-time
select(onchange='{ _update }')
option(each="{ hours }", value='{ hour }', selected="{ selected }") { hour }
script.
const self = this;
function range(start, end) {
return Array.apply(Array, Array(1 + end - start)).map((_, i) => {
return i + start;
});
}
this.hours = range(opts.dayStart + 1, 24).map((hour) => {
return {
hour: hour,
selected: opts.cronTime === hour ? true : false
};
});
let url = '/users/update';
_update(e) {
$.post(url,
{
cronTime: e.target.value
},
(data, status) => {
console.log(data);
console.log(status);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment