Skip to main content

Posts

AngularJS - Build a custom validation directive for using multiple emails in textarea

AngularJS already supports the built-in validation with text input with type email. Something simple likes the following: <input name="input" ng-model="email.text" required="" type="email" /> <span class="error" ng-show="myForm.input.$error.email"> Not valid email!</span> However, I used a text area and I wanted to enter some email addresses that's saparated by a comma (,). I had a short research and it looked like AngualarJS has not supported this functionality so far. Therefore, I needed to build a custom directive that I could add my own validation functions. My validation was done only on client side, so I used the $validators object. Note that, there is the $asyncValidators object which handles asynchronous validation, such as making an $http request to the backend. This is just my implementation on my project. In order to understand that, I supposed you already had experiences with

9 Most important characters of business emails in English

1. Clarity - The content should be simple, easily to follow, short words rather than long one. - Use the  active voice,  positive words rather than complaint one.  2. The "One Thing" rule - Keep the message focused. The another thing should be written in another email. 3. Be political - The message is in more the two paragraphs, it should be reduced. - Use "Please" and "thank you" - Use phrase that states you are not sure of something: I think that..., It is possible..., The optimal solution... 4. Meaning Subject Bad: Important. Please read Better: Meeting set for tomorrow at 10AM - Need a room 5. Think before you write - Don't send e-mails in haste - Avoid using context (background information) 6. Understand you Audience - What they like to hear - See your writing from their perspective 7. Sign-off like a professional - Add signature block with appropriate contact information 8. Make sure no errors with spelling and g

How did I start practising BDD?

In the beginning days, I have practiced TDD (Test Driven Development) using JUnit, I approached that I should test methods belong to a class. For example: I have a class with some methods: public class A{ public void method1(){ } public void method2(){ } } And then, I wrote some test methods to check the corresponding ones, for example: public class ATest{ @Test public void testMethod1(){ .... assertTrue(...); ..... assertEquals(...); } @Test public void testMethod2(){ } } After that, I know that a test method (ex: testMethod1) should just only test one thing, so I decided to write more methods for each case. It looks like the following: @Test public void testMethod1_When_Case1(){ .... assertTrue(...); } @Test public void testMethod1_When_Case2(){ .... assertEquals(...); } However, it was not a really good approach because it seems that I just focused on test the functionality of the method of the class. With the TDD approach, I knew that I s

Adding a default text to the beginning of an text area

I have a text area where I can enter a SQL statement. The text "SELECT TOP 1" is used at the begining of the sql statement as a default prefix that can not be removed. In order to archive this functionality, I found three options: 1. Use an inputMask and build a pattern for the entered text. We can use the prefix inside the text area: http://jsfiddle.net/SEXAj/2130/ 2. Create an javascript event listener on event "input" and calculate to prevent the prefix is removed http://jsfiddle.net/sarbbottam/TUc94/ 3. Use another html tag like "div"/"span" that contains the prefix and calculate the suitable position + Tag "span": http://jsfiddle.net/4YzZy/ + Tag "div": http://jsfiddle.net/215b34fs/ I chose the 3rd approach with tag "div" because it's the most easiest solution and suitable for me at that monment. References: [1].  http://stackoverflow.com/questions/24846041/how-do-i-add-a-default-text

Strategy Design Pattern

For example, I have a program with an Animal abstract class and two sub-classes Dog and Bird. I want to add new behavior for the class Animal, this is "fly".  Now, I face two approaches to solve this issue: 1. Adding an abstract method "fly" into the class Animal. Then, I force the sub-classes should be implemented this method, something like: public abstract class Animal{ //bla bla public abstract void fly(); } public class Bird extends Animal{ //bla bla public void fly(){ System.out.println("Fly high"); } } public class Dog extends Animal{ //bla bla public void fly(){ System.out.println("Cant fly"); } } 2. Creating an interface with method "fly" inside. The same issue to an abstract class, I force the classes these implement this interface should have a method "fly" inside: public interface Flyable{ public void fly(); } public class Bird implements Flyable{ //bla bla public void fly(){ System.out.pr

AngularJS Fundamentals

1. Single Page Application (SPA) - Single page application versus   Traditional multi-page - " Single-Page Applications (SPAs) are Web apps that load a single HTML page and dynamically update that page as the user interacts with the app. SPAs use AJAX and HTML5 to create fluid and responsive Web apps, without constant page reloads. However, this means much of the work happens on the client side, in JavaScript " src:  https://msdn.microsoft.com/en-us/magazine/dn463786.aspx - " Web browser JavaScript frameworks, such as AngularJS, Ember.js, ExtJS and React have adopted SPA principles " src:  https://en.wikipedia.org/wiki/Single-page_application 2. Directive and Data Binding Expression <!DOCTYPE html> <html lang="en-US"> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> <body> <div ng-app=""> <p>Name : <input type="text" ng