Select Page

Category: Article

Prefilling a Date Input

HTML has a special input type for dates, like this: . In supporting browsers (pretty good), users will get UI for selecting a date. Super useful stuff, especially since it falls back to a usable text input. But how do you set it to a particular day? To set a particular day, you’ll need to set the value to a YYYY-MM-DD format, like this: Minor note: placeholder won’t do anything in a browser that supports date inputs. Date inputs can have min and max, so only a date between a particular range can be selected. Those take the same format. Just for fun we’ve used a step value here to make only Tuesday selectable: How about defaulting the input to the value of today? Unfortunately, there is no HTML-only solution for that, but it’s possible with JavaScript. let today = new Date().toISOString().substr(0, 10); document.querySelector("#today").value = today; // or... document.querySelector("#today").valueAsDate = new Date(); It’s also possible to select a specific week or month. Prefilling those is like this: If you need both date and time, there is an input for that as well. Just for fun Or just time! Here we’ll use step again just for fun to limit it to 15 minute increments: Live Demo See the Pen Prefilling HTML date inputs by Chris Coyier (@chriscoyier) on CodePen. Support This browser support data is from Caniuse, which has more...

Read More

JavaScript Scope and Closures

Scopes and closures are important in JavaScript. But, they were confusing for me when I first started. Here’s an explanation of scopes and closures to help you understand what they are. Let’s start with scopes. Scope A scope in JavaScript defines what variables you have access to. There are two kinds of scope – global scope and local scope. Global scope If a variable is declared outside all functions or curly braces ({}), it is said to be defined in the global scope. This is true only with JavaScript in web browsers. You declare global variables in Node.js differently,...

Read More

Form Validation with Web Audio

I’ve been thinking about sound on websites for a while now. When we talk about using sound on websites, most of us grimace and think of the old days, when blaring background music played when the website loaded. Today this isn’t and needn’t be a thing. We can get clever with sound. We have the Web Audio API now and it gives us a great deal of control over how we design sound to be used within our web applications. In this article, we’ll experiment with just one simple example: a form. What if when you were filling out...

Read More

Implementing Push Notifications: Setting Up & Firebase

You know those the little notification windows that pop up in the top right (Mac) or bottom right (Windows) corner when, for example, a new article on our favorite blog or a new video on YouTube was uploaded? Those are push notifications. Part of the magic of these notifications is that they can appear even when we’re not currently on that website to give us that information (after you’ve approved it). On mobile devices, where supported, you can even close the browser and still get them. Article Series: Setting Up & Firebase (You are here!) The Back End (Coming...

Read More

Double Opt-In Email Intros

You know those those “introduction” emails? Someone thinks you should meet someone else, and emails happen about it. Or it’s you doing the introducing, either by request or because you think it’s a good idea. Cutting to the chase here, those emails could be done better. Eight years ago, Fred Wilson coined the term “double opt-in intro”. This is how it can work. You’re doing the vetting Since you’re writing the emails here, it’s your reputation at stake here. If you do an introduction that is obnoxious for either side, they’ll remember. Make sure you’re introducing people that you really do think should know each other. Like a bizdev cupid. You’re gonna do two (or three) times writing The bad way to do an intro is to email both people at once. Even if this introduction has passed your vetting, you have no idea how it’s going to turn out. There is a decent chance either of them or both aren’t particularly interested in this, which makes you look like a dolt. It doesn’t respect either of their time, puts your reputation at risk, and immediately puts everyone into an awkward position (if they ignore it they look like an asshole). Instead, you’re going to write two emails, one to each person you’re trying to introduce. And you’re not going to reveal who the other person is, except with...

Read More

Visual Email Builder Apps

I bet y’all know that apps like Campaign Monitor and MailChimp have visual email builders built right into them. You drag and drop different types of content right into a layout. You edit text right within the email. It’s nice. It’s a lot nicer than editing the quagmire of HTML underneath, anyway! But not everybody needs all the rest of the features that those apps bring, like list management and the actual sending of the email. Perhaps you have an app that already handles that kind of thing. You just need to design some emails, get the final HTML,...

Read More

A Poll About Pattern Libraries and Hiring

I was asked (by this fella on Twitter) a question about design patterns. It has an interesting twist though, related to hiring, which I hope makes for a good poll. Note: There is a poll embedded within this post, please visit the site to participate in this post’s poll. I’ll let this run for a week or two. Then (probably) instead of writing a new post with the results, I’ll update this one with the results. Feel free to comment with the reasoning for your vote. Results! At the time of this update (September 2017), the poll has been up for about 6 weeks. 61% of folks said they would be more likely to want a job somewhere that were actively using (or working toward) a pattern library. That’s a strong number I’d say! Especially when 32% of folks responded that they don’t care. So for 93% of folks, they either are incentivized to work for you because of a pattern library or don’t mind. So is a pattern library good not only for your codebase and business, for attracting talent as well. Only 7% of folks would be less likely to want to work there. Presumably, that’s either because they enjoy that kind of work and it’s already done, or find it limiting. Read the comments below for some interesting further thoughts. A Poll About Pattern Libraries and...

Read More

Using ES2017 Async Functions

ES2017 was finalized in June, and with it came wide support for my new favorite JavaScript feature: async functions! If you’ve ever struggled with reasoning about asynchronous JavaScript, this is for you. If you haven’t, then, well, you’re probably a super-genius. Async functions more or less let you write sequenced JavaScript code, without wrapping all your logic in callbacks, generators, or promises. Consider this: function logger() { let data = fetch('http://sampleapi.com/posts') console.log(data) } logger() This code doesn’t do what you expect. If you’ve built anything in JS, you probably know why. But this code does do what you’d expect. async function logger() { let data = await fetch('http:sampleapi.com/posts') console.log(data) } logger() That intuitive (and pretty) code works, and its only two additional words! Async JavaScript before ES6 Before we dive into async and await, it’s important that you understand promises. And to appreciate promises, we need go back one more step to just plain ol’ callbacks. Promises were introduced in ES6, and made great improvements to writing asynchronous code in JavaScript. No more “callback hell”, as it is sometimes affectionately referred to. A callback is a function that can be passed into a function and called within that function as a response to any event. It’s fundamental to JS. function readFile('file.txt', (data) => { // This is inside the callback function console.log(data) } That function is simply logging the...

Read More

How do you start a sentence with “npm”?

This npm. Asking this question was a fun little journey. Right on the npm website, the very first sentence starts with “npm”, and they do not capitalize it. That’s a pretty good precedent for not capitalizing it. It certainly looks awkward though, which is why I asked the question to begin with. It doesn’t feel right to me to start a sentence that way, and I’m sure other some other people would look at it and see a mistake. Their own documentation forbids capitalization as well: Straight from Raquel Vélez, an employee: always npm, even if starting the sentence....

Read More
www.000webhost.com