Skip to content

Commit

Permalink
Merge pull request #30 from bigcommerce/formfix
Browse files Browse the repository at this point in the history
Added form validation models and swapped search remote api
  • Loading branch information
hegrec committed Jun 16, 2015
2 parents 0039fb7 + 028bc98 commit 4ecbaef
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 15 deletions.
26 changes: 12 additions & 14 deletions src/api/search.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import _ from 'lodash';
import Remote from './remote';
import Hooks from '../hooks';
import Base from './base';

export default class extends Remote
export default class extends Base
{
/**
* @Constructor
Expand All @@ -12,25 +11,24 @@ export default class extends Remote
super();

// set up class variables
this.endpoint = '/search';
this.endpoint = '/search.php?search_query=';
}

/**
* Get search results
* @param {String} query
* @param {Object} options
* @param {Object} params
* @param {Function} callback
*/
search(query, options, callback) {
let defaultOptions = {
params: {},
headers: {}
};
search(query, params, callback) {
let url = this.endpoint + encodeURIComponent(query);

options = _.assign({}, defaultOptions, options);
options.params.search_query = encodeURIComponent(query);
if (typeof params === 'function') {
callback = params;
params = {};
}

Hooks.emit('search-quick-remote', options);
this.makeRequest(this.endpoint, 'GET', options, callback);
Hooks.emit('search-quick-remote', query);
this.makeRequest(url, 'GET', params, false, callback);
}
}
6 changes: 5 additions & 1 deletion src/forms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import LoginForm from './forms/login';
import CreateAccountForm from './forms/create_account';
import EditAccountForm from './forms/edit_account';
import AddressForm from './forms/address';

export default {
login: new LoginForm(),
create_account: new CreateAccountForm()
create_account: new CreateAccountForm(),
edit_account: new EditAccountForm(),
address: new AddressForm()
};
45 changes: 45 additions & 0 deletions src/forms/edit_account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export default class {
/**
* @Constructor
*/
constructor() {

}

firstName(value) {
return value.length;
}

lastName(value) {
return value.length;
}

email(value) {
let re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

return re.test(value);
}

phone(value) {
value.length;
}

password(value) {
let r1 = /[A-Za-z]/, // alphabetic
r2 = /[0-9]/; // numeric

if (!r1.test(value)) {
return false;
}

if (!r2.test(value)) {
return false;
}

return value.length >= 7;
}

passwordMatch(password1, password2) {
return password1 === password2;
}
}

0 comments on commit 4ecbaef

Please sign in to comment.