Skip to content

Instantly share code, notes, and snippets.

@tbuyle
tbuyle / application.js
Created January 9, 2012 16:18
Formtastic Datepicker field.
$(function() {
$("INPUT.datepicker").datepicker();
}
@tbuyle
tbuyle / datepicker_patch.js
Last active January 23, 2020 09:39
Set Bootstrap Datepicker to focusDate when tabbing out
# datepicker is accessible trough data("datepicker")
# but its focusDate is cleared out on keydown for tab (9)
# my solution is thus to store the focusDate as data('datepicker_focusdate') on keydown when the key is a navigation key (up, down, left, right)
# and then set the datepicker date to that date when tabbing out
$("body").on("keydown", '[data-provide~=datepicker]', function(e){
if ([37,38,39,40].indexOf(e.keyCode) >= 0 ) {
$(this).data('datepicker_focusdate', $(this).data("datepicker").focusDate)
} else if (e.keyCode == 9 && $(this).data('datepicker_focusdate')) {
$(this).datepicker('update', $(this).data('datepicker_focusdate'));
@tbuyle
tbuyle / application.rb
Last active August 3, 2016 09:20
Rails Custom Validator for email with I18n message. Regex is simple but should be enough. Add https://github.com/mailcheck/mailcheck for even less invalid emails :-)
# config/application.rb
[...]
config.autoload_paths += %W["#{config.root}/app/validators/"]
[...]
@tbuyle
tbuyle / html_template_controller.js
Last active May 23, 2024 23:33
Load external HTML template and append them to the document body (Stimulus.js)
import { Controller } from "stimulus"
export default class extends Controller {
connect() {
const templates = this.element.import.querySelectorAll("template");
templates.forEach(function(template) {
document.querySelector('body').appendChild(template);
});
}
}
def self.multi_scope(scopes)
my_scopes = Array.new
scopes.each do |scope|
m_scopes << self.send(scope) if self.respond_to? scope
end
if my_scopes.length == 0
return slef.none
else
f = my_scopes.delete_at(0)
my_scopes.each do |s|
@tbuyle
tbuyle / _select2_material.scss
Created June 22, 2020 07:18
SCSS fir Select2 with Daemonite's Material
.select2-container, .select2-container--material {
ul {
margin: 0;
padding: 0;
}
.select2-selection, .select2-selection--single, .select2-selection--multiple {
@extend .form-control;
/*@extend .d-flex;*/
@tbuyle
tbuyle / _alert.scss
Last active June 25, 2020 07:12
Material Alert (prototype for djibe / material)
.alert {
background-color: #fff;
border-top-left-radius: 0;
border-top-right-radius: 0;
border-top: 0;
border-left: 0;
.container:before {
@extend .navbar-toggler-icon;
content: "info";
vertical-align: middle;