javascript
In Javascript, why is the “this” operator inconsistent?
Quick advice on best practices before I babble on about the magic this variable. If you want Object-oriented programming (OOP) in Javascript that closely mirrors more traditional/classical inheritance patterns, pick a framework, learn its quirks, and don’t try to get clever. If you want to get clever, learn javascript as a functional language, and avoid … Read more
prevent default action for tab key in chrome?
input.keydown(function(event){ if (event.keyCode === 9) { event.preventDefault(); } }) On keyup is too late, you need to call the event on keydown. That worked for me.
Remove shadow/background glow on highcharts data label?
Set dataLabels.styles.textShadow to false. plotOptions: { columnrange: { // or general options: “series: { … }” dataLabels: { enabled: true, color: ‘red’, style: { textShadow: false } } } }, Demo: http://jsfiddle.net/oe1vcmqj/2/ EDIT: Since Highcharts 5.0.3, the option name is textOutline. plotOptions: { columnrange: { // or general options: “series: { … }” dataLabels: { … Read more
How to invalidate a TextField in Material UI
As of 0.20.1 you can helperText and error props <TextField hintText=”Phone” error ={this.state.errorText.length === 0 ? false : true } floatingLabelText=”Phone” name=”phone” helperText={this.state.errorText} onChange={this.onChange.bind(this)}/>
using external JS libraries in my angular 2 project
If you use angular-cli, you can add all your external JS files in assets folder. And then in angular-cli.json add them: “scripts”: [ “../node_modules/jquery/dist/jquery.min.js”, “../node_modules/bootstrap/dist/js/bootstrap.min.js”, “../node_modules/moment/moment.js”, “../node_modules/chart.js/dist/Chart.bundle.min.js”, “../node_modules/chart.js/dist/Chart.min.js”, “../node_modules/ng2-datetime/src/vendor/bootstrap-datepicker/bootstrap-datepicker.min.js”, “./assets/js/slimscroll.min.js”, “./assets/js/inspinia.js”, “./assets/js/metisMenu.js”, “./assets/js/footable.all.min.js” ] You can do it also with external styles: “styles”: [ “../node_modules/ng2-toastr/bundles/ng2-toastr.min.css”, “../node_modules/bootstrap-sass/assets/stylesheets/_bootstrap.scss”, “../node_modules/font-awesome/scss/font-awesome.scss”, “../node_modules/ng2-datetime/src/vendor/bootstrap-datepicker/bootstrap-datepicker3.min.css”, “./assets/scss/plugins/footable/footable.core.css”, “./assets/scss/style.scss” ] And of course you … Read more
JavaScript: remove an event listener from within that listener?
You can pass the once option to have a listener act only once, then remove itself. Docs: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Parameters Example: element.addEventListener(‘eventname’, (ev) => { console.log(“event is captured only once.”); // do more stuff… }, { once: true }); From the same docs link above, modern browser support is good, but is not available for Internet Explorer.
How to prepend a zero in front of any number below 10 in Javascript using Regexp
Just add the leading 0 every time, then use slice(-2) to get the last two characters, like so: (‘0’ + currentDate.getHours()).slice(-2)
Get the current value in bootstrap-select
I think the answer may be easier to understand like this: $(‘#empid’).on(‘click’,function() { alert($(this).val()); console.log($(this).val()); }); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js”></script> <select id=”empid” name=”empname” multiple=”multiple”> <option value=”0″>item0</option> <option value=”1″>item1</option> <option value=”2″>item2</option> <option value=”3″>item3</option> <option value=”4″>item4</option> </select> <br /> Hold CTRL / CMD for selecting multiple fields If you select “item1” and “item2” in the list, the output will … Read more
TypeError: exphbs is not a function
You should use “exphbs.engine” instead of “exphbs”. app.engine(‘.hbs’, exphbs.engine({ extname: ‘.hbs’, defaultLayout: “main”}));