Showing posts with label Tech. Show all posts
Showing posts with label Tech. Show all posts

Wednesday, September 26, 2018

React JS set focus on a input

Use the prop autoFocus in a input to make it auto focus

eg:

<input autoFocus className="btn" type="text" />

Monday, September 17, 2018

React JS send custom parameter to onClick

If you need to send a custom parameter to your onClick event handler, do like this

<a href="" onClick={()=> {this.tabClicked("Exceptions")}}>Exceptions</a>

if you need to pass the event as well to the onClick handler use like this

<a href="" onClick={(evt)=> {this.tabClicked(evt,"Exceptions")}}>Exceptions</a>


and in your tabClicked() you can get the parameters like this

tabClicked(evt, tab) {
evt.preventDefault(); // Let's stop this event.
alert(tab); // should alert Exceptions
}

Sunday, May 13, 2018

Bootstrap - show text in a single link

To show text in a single line you need to added the Bootstrap class "text-nowrap"

Example
<span class="nowrap">Your text here.</span>

JavaScript - Check if object is empty

function isEmptyObject ( obj ) {
    var name;
    for ( name in obj ) {
        return false;
    }
    return true;
}

Friday, April 20, 2018

JavaScript set object key by variable

ES6

var key = "name";
var person = {[key]:"John"};
console.log(person); // should print  Object { name="John"}

Before ES6

var person = {};
var key = "name";

person[key] /* this is same as person.name */ = "John";

console.log(person); // should print  Object { name="John"}

Thursday, April 19, 2018

Give random colors to text in a page using D3

d3.selectAll("*").style("color", function() {
  return "hsl(" + Math.random() * 360 + ",100%,50%)";
});

Get Indian financial year based on date

This function lets you get the start and end date of Indian financial year based on given date. This can also be modified for US financia...