Meteor.js : add a date picker to a page - meteor

I'm trying hard to get a date picker on my meteor application. I tested lot of packages found by googling, but none seems to work, or, probably, I'm doing it wrong. Can someone tell me clearly how to add a date picker?
Thanks a lot!

I would use the bootstrap 3 package and the bootstrap 3 date time picker package:
$ meteor add twbs:bootstrap
$ meteor add tsega:bootstrap3-datetimepicker
Then, simply add the form in your HTML file:
<template name="myTemplate">
<form>
<div class="form-group">
<label for="myInput">Input name</label>
<div class="input-group datetimepicker">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
<input name="idInput" id="idInput" class="set-due-date form-control" type="text"/>
</div>
</div>
</form>
</template>
And in your corresponding JavaScript file, you have to initialize your date time picker:
Template.myTemplate.rendered = function(){
$('.datetimepicker').datetimepicker();
};
And if you have different date input in your page (for example):
Template.myTemplate.rendered = function(){
$('.datetimepicker').each(function(){
$(this).datetimepicker();
});
}
Finally, I invite you to read the Documentation if you need more options (like date format etc).
Hope it will help you!

I use the one from eonasdon (Bootstrap required) and you get get it prepackaged by doing this:
meteor add hujhax:bootstrap3-datetimepicker

I have these packages added
twbs:bootstrap
jquery
rajit:bootstrap3-datepicker
and used this in the template
<div class="box-body no-padding">
<!--The calendar -->
<div id="calendar" style="width: 100%"></div>
</div><!-- /.box-body -->
and added helper below
Template.myCalendar.rendered = function() {
$('#calendar').datepicker();
}

Related

Bootstrap validation : 2 glyphicons are overlapping

I have validation for 2 fields which are country code and actual mobile number. I have attached screenshot. When correct country code is given and invalid mobile no is given at that time correct tick glyphicon for country code and cross glyphicon comes which overlaps on each other. I need to remove glyphicon for country code by using css or js. Any help will be appreciated.
If you're using jQuery:
let's say you have
<div class="container">
<div class="form">
form content...
</div>
</div>
you would call:
$('.container form .glyphicon').each(function(i){ // your target input id or class should be placed between 'form' and '.glyphicon' eg: $('.container form input[name=state_code] .glyphicon')
if (i!=0) $(this).remove();
});
this way you get rid of the additional Xes appearing when you don't need.
I have found the answer. I have done it by using jQuery.
My actual HTML was as below,
<div class="input-group">
<div class="input-group-addon">+</div>
<input type="tel" maxlength="3" class="form-control pull-left" id="CountryCode" name="CountryCode" placeholder="Code">
<input data-bv-field="Mobile" type="text" id="Mobile" name="Mobile" class="form-control">
</div>
Bootstrap creates glyphicons for correct and wrong below the html as below,
<i class="form-control-feedback bv-no-label bv-icon-input-group glyphicon glyphicon-ok" data-bv-icon-for="CountryCode" style=""></i>
<i class="form-control-feedback bv-no-label bv-icon-input-group glyphicon glyphicon-ok" data-bv-icon-for="Mobile" style=""></i>
So I have added following one line code to remove correct and wrong glyphicons for country code field,
$("#CountryCode").parent().next().removeClass('glyphicon-ok glyphicon-remove');

What is the best way to validate input (Skeleton + Vue.js)?

I realy like this tools, because of their simplicity and compactness. But sometimes I face lack of plugins / snippets (my JS skills also pretty weak, usually I'm backend developer), so here's one of those cases:
For example, I have simple form like this one:
<div class="row">
<div class="six columns">
<label for="email">Contact email*</label>
<input v-model="email" class="u-full-width" type="email" id="email" placeholder="admin#exchange.com" name="email">
</div>
<div class="six columns">
<label for="date">Launch date*</label>
<input v-model="date" class="u-full-width" type="text" id="date" placeholder="June, 2014">
</div>
</div>
As you can see, I want to make this fields required, email input should be in email format, something like ***#***.***, date field can be anything.
What is the best way to realize it? Also I've found 3 Vue plugins, who's your favorite?
vue-validator
vee-validate
vue-form
Thanks for any examples/snippets/etc
Since you come from backend and are not expert with JS ( neither am I :D ) I suggest you do it yourself. You will learn more.
This is how I would do it:
<input name="email" v-model="email" #keyup="validateEmail()" />
... vue component or instance ...
data: function() { // if you are doing this on Vue instance and not component then data property will look differently but if in component it has to be a function that returns an object
return {
email: ""
}
},
methods: {
validateEmail: function() {
console.log(this.email)
// here you have access to email input as it changes so you can use either regex or substring or some other string manipulation to determine if the string satisfies your criteria
}

AngularJS ng-style with ng-model scope variable

I'm building a website to let users design their own mobile app. One side of the website has a form that the user fills out, and the other side has a live preview of the app based off of the form data. This is how it is set up:
Controller:
$scope.primaryColor = "#325490";
Form Input:
<!-- Primary Color -->
<div class="form-group">
<label for="primaryColor" class="col-sm-2 control-label">Primary:</label>
<div class="col-sm-10">
<input type="text" class="form-control" ng-model="$parent.primaryColor">
</div>
</div>
Live Preview:
<div class="mockView" ng-style="{'background-image':'url({{$parent.backgroundFile}})', 'background-color':'{{$parent.primaryColor}}'}">
I have to use $parent because I am using ng-include on my index page to include the form.htm and preview.htm files. I have tested the form and I know it is changing all of the scope variables that I have, but the previewer is not changing. Any help is appreciated!
Remove {{}} and '' and it should work, like this:
<div class="mockView" ng-style="{'background-image':'url({{$parent.backgroundFile}})', 'background-color': $parent.primaryColor }">

ng-keyup doesn't do function

I'm trying to figure out how ng-keyup works and I found some tutorials and sources, but when I tried to make one myself it doesn't work. You can see my codepen example here, http://codepen.io/alucardu/pen/XbOWRP and this is a JSfiddle example I tried to recreate http://jsfiddle.net/r74a5m25/.
html
<div ng-app>
<div ng-controller="exampleCtrl">
<input ng-model="test" ng-keyup="search()" />
<br/>
<span>{{test}}</span>
</div>
</div>
javascript
function exampleCtrl($scope) {
$scope.search = function() {
alert('test');
};
}
This problem come from the version of your angular. The earliest doc I can find in angularjs about ng-keyup is on the version 1.1.2. And you are using the previous version, 1.1.1.
Personnaly, I try with 1.2.0 in your codepen and it works
: https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js
This version is use in the JSFiddle that's why it works fine there.
You didn't use ng-keyup in the example. You have to bind your function to your input, just like you do with ng-model:
<input ng-model="test" ng-keyup="search()"/>
You need to try down with latest version of angularjs. The formats should be maintained.
<div ng-app="testApp">
<div ng-controller="exampleCtrl">
<input ng-model="test" ng-keyup="search()" />
<br/>
<span>{{test}}</span>
</div>
</div>
Javascript
myApp = angular.module("testApp",[]);
myApp.controller("exampleCtrl",function($scope){
$scope.search=function(){
alert("test");
}
});

Can't get parsley.js to work with meteor using javascript in rendered

I try to use parsley for validation with meteor following this question: Using Parsley.js with Meteor using HTML Code
I run meteor 0.6.6.3 on Ubuntu 13.10, added package jquery and added parsley 1.1.7 from atmosphere (https://atmosphere.meteor.com/package/parsleyjs) with meteorite.
I also tested with the current version 1.2.2 of parsley from client/lib (after removing parsleyjs with mrt).
Knowing that I can't use the HTML markup for validation I created a template like this
<template name="new_customer">
<form id="new_customer_form">
<div class="newCustomer">
<div class="lookupcell">
<input type="text" size="1"
name="new-customer-name"
id="new-customer-name"
class="new-customer-name"
placeholder="neue Firma/Person"
parsley-notblank="true" />
</div>
<div class="lookupcell">
<input type="text" size="1" id="new-customer-email"
name="new-customer-email"
id="new-customer-email"
parsley-type="email"
parsley-trigger="keyup"
class="new-customer-email" placeholder="Email" />
</div>
</div>
<div style="text-align: right;">
<button type="submit">Add</button>
</div>
</form>
</template>
and the following javascript for setup
Template.new_customer.rendered = function () {
console.log("rendered new_customer");
$new_customer_form = $( '#new_customer_form' );
if (! $new_customer_form) {
console.log("form not found.");
return;
}
$new_customer_form.parsley();
$new_customer_form.parsley( 'addItem', '#new_customer_name' );
};
meteor crashes on rendering at the last line when I try to add the field #new_customer_name with the following stacktrace
[09:44:11.969] "Exception from Deps afterFlush function: ParsleyForm.prototype.addItem#http://localhost:3000/packages/parsleyjs.js?ed9f338553f590de7edeb7b3e5ca8cb568f2e74d:1152
bind#http://localhost:3000/packages/parsleyjs.js?ed9f338553f590de7edeb7b3e5ca8cb568f2e74d:1295
$.fn.parsley#http://localhost:3000/packages/parsleyjs.js?ed9f338553f590de7edeb7b3e5ca8cb568f2e74d:1305
Template.new_customer.rendered#http://localhost:3000/client/X4Lizenzen.js?7d0644137e559b675577266ad6e2f78f087b3453:151
Template.__define__/partial/html</html<.rendered#http://localhost:3000/packages/templating.js?5944cd5e16b26fbf83959a0fe92d7754029a624d:181
scheduleOnscreenSetup/</<#http://localhost:3000/packages/spark.js?3a050592ceb34d6c585c70f1df11e353610be0ab:443
_.forEach#http://localhost:3000/packages/underscore.js?13ab483e8a3c795d9991577e65e811cd0b827997:130
scheduleOnscreenSetup/<#http://localhost:3000/packages/spark.js?3a050592ceb34d6c585c70f1df11e353610be0ab:441
.flush#http://localhost:3000/packages/deps.js?5ac28feec1f3e0539889ecde598dd9d01e408b41:265
"
The stack does not tell me what the actual problem is (or rather I don't understand :-)
So I wonder how the author of the linked question got his setup to work at all with the setup in rendered(). Any ideas anyone?
Update: It turns out I made a simple mistake which I did not spot until this morning.
I had id="new-customer-name" in the template and tried to register the filed with parsley using #new_customer_name. This cannot work and what is more, hyphens cannot be used for id-strings. After correcting the error it worked.
I guess you need to add the data-parsley-validate as given below. if its working without using that let me know. I am wondering how did it render with using data-parsley-validate in form.
form id="new_customer_form" data-parsley-validate

Resources