From 87a3791071a12783f1d51a4c9fd870980ec87764 Mon Sep 17 00:00:00 2001 From: Federico Zivolo Date: Tue, 23 Sep 2014 10:28:01 +0200 Subject: [PATCH] added support for dynamically added inputs --- scripts/material.js | 47 +++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/scripts/material.js b/scripts/material.js index c5653288..e5b60682 100644 --- a/scripts/material.js +++ b/scripts/material.js @@ -4,32 +4,37 @@ $(function (){ ripples.init(".btn:not(.btn-link), .navbar a, .nav-tabs a, .withripple"); - // Add fake-checkbox to material checkboxes - $(".checkbox > label > input").after(""); + $(document).bind("DOMSubtreeModified", function(){ + // Add fake-checkbox to material checkboxes + $(".checkbox > label > input").not(".bs-material").addClass("bs-material").after(""); - // Add fake-radio to material radios - $(".radio > label > input").after(""); + // Add fake-radio to material radios + $(".radio > label > input").not(".bs-material").addClass("bs-material").after(""); - // Add elements for material inputs - $("input.form-control, textarea.form-control, select.form-control").each( function() { - $(this).wrap("
"); - $(this).after(""); - if ($(this).hasClass("floating-label")) { - var placeholder = $(this).attr("placeholder"); - $(this).attr("placeholder", null).removeClass("floating-label"); - $(this).after("
" + placeholder + "
"); - } - if ($(this).is(":empty") || $(this).val() === null || $(this).val() == "undefined" || $(this).val() === "") { - $(this).addClass("empty"); - } + // Add elements for material inputs + $("input.form-control, textarea.form-control, select.form-control").not(".bs-material").each( function() { + $(this).addClass("bs-material"); + $(this).wrap("
"); + $(this).after(""); + if ($(this).hasClass("floating-label")) { + var placeholder = $(this).attr("placeholder"); + $(this).attr("placeholder", null).removeClass("floating-label"); + $(this).after("
" + placeholder + "
"); + } + if ($(this).is(":empty") || $(this).val() === null || $(this).val() == "undefined" || $(this).val() === "") { + $(this).addClass("empty"); + } + + if ($(this).parent().next().is("[type=file]")) { + $(this).parent().addClass("fileinput"); + var $input = $(this).parent().next().detach(); + $(this).after($input); + } + }); - if ($(this).parent().next().is("[type=file]")) { - $(this).parent().addClass("fileinput"); - var $input = $(this).parent().next().detach(); - $(this).after($input); - } }); + $(document).on("keyup change", ".form-control", function() { var self = $(this); setTimeout(function() {