Skip to content

Commit

Permalink
Updated project structure and included DateVal
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusLongmuir committed Oct 16, 2014
1 parent e367eea commit a32a13b
Show file tree
Hide file tree
Showing 21 changed files with 5,030 additions and 1,084 deletions.
12 changes: 12 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
coverage
docs
docs_src
examples
node_modules
src
test
.gitignore
.travis.yml
gulpfile.js
link.sh
.gitignore
33 changes: 24 additions & 9 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
{
"name": "fieldval-all",
"version": "0.0.1",
"devDependencies": {
"fieldval" : "FieldVal/fieldval-js",
"fieldval-basicval" : "FieldVal/fieldval-basicval-js",
"fieldval-ui" : "FieldVal/fieldval-ui",
"fieldval-rules" : "FieldVal/fieldval-rules-js"
},
"private": true
"name": "fieldval-all",
"version": "0.1.0",
"main": "fieldval-all.js",
"ignore": [
"coverage",
"docs",
"docs_src",
"examples",
"node_modules",
"src",
"gulpfile.js",
".gitignore",
"test",
".travis.yml",
"link.sh",
".gitignore"
],
"devDependencies": {
"fieldval" : "0.1.3",
"fieldval-basicval" : "0.1.3",
"fieldval-dateval" : "0.1.1",
"fieldval-ui" : "0.1.1",
"fieldval-rules" : "0.1.3"
}
}
1 change: 0 additions & 1 deletion bower_components/fieldval-ui

This file was deleted.

29 changes: 29 additions & 0 deletions bower_components/fieldval-ui/.bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "fieldval-ui",
"version": "0.1.1",
"main": "fieldval-ui.js",
"ignore": [
"bower_components",
"docs",
"docs_src",
"examples",
"node_modules",
"src",
"gulpfile.js",
".gitignore"
],
"devDependencies": {
"jquery": "1.11.1",
"nestable": "FieldVal/Nestable"
},
"homepage": "https://github.com/FieldVal/fieldval-ui",
"_release": "0.1.1",
"_resolution": {
"type": "version",
"tag": "v0.1.1",
"commit": "404b23466bfb719d5519aefba9ea22cd5f343aa1"
},
"_source": "git://github.com/FieldVal/fieldval-ui.git",
"_target": "0.1.1",
"_originalSource": "fieldval-ui"
}
3 changes: 3 additions & 0 deletions bower_components/fieldval-ui/.bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "bower_components"
}
2 changes: 2 additions & 0 deletions bower_components/fieldval-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fieldval-ui
===========
19 changes: 19 additions & 0 deletions bower_components/fieldval-ui/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "fieldval-ui",
"version": "0.1.1",
"main": "fieldval-ui.js",
"ignore": [
"bower_components",
"docs",
"docs_src",
"examples",
"node_modules",
"src",
"gulpfile.js",
".gitignore"
],
"devDependencies": {
"jquery": "1.11.1",
"nestable": "FieldVal/Nestable"
}
}
110 changes: 110 additions & 0 deletions bower_components/fieldval-ui/example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<script src="bower_components/jquery/dist/jquery.js"></script>

<script src="node_modules/fieldval/fieldval.js"></script>
<script src="node_modules/fieldval-basicval/fieldval-basicval.js"></script>
<script src="node_modules/fieldval-dateval/fieldval-dateval.js"></script>
<script src="fieldval-ui.js"></script>

<!-- Apply the "minimal" theme to FieldVal-UI -->
<link rel="stylesheet" type="text/css" href="themes/minimal.css">
<script src="themes/minimal.js"></script>

<style type="text/css">
body{
font-family: "Helvetica";
}
</style>

<script>
$(document).ready(function(){
var form = new FVForm();
var output;

//values and displayed names
var gender_choices = [
["m","Male"],
["f","Female"]
];
var date_format = "yyyy/MM/dd hh:mm:ss";

Field.prototype.show_error = function(){
var field = this;
field.error_message.slideDown();
}

form.add_field("first_name", new TextField("First Name"));
form.add_field("last_name", new TextField("Last Name"));
form.add_field("join_date", new DateField("Join Date", {
format: date_format
}));
form.add_field("gender", new ChoiceField("Gender",{
choices: gender_choices
}));
form.add_field("email", new TextField("Email"));
form.add_field("bio", new TextField("Bio","textarea"));

var array_field = new ArrayField("Tags");
array_field.new_field = function(index){
var tag_field = new TextField("Tag")
array_field.add_field(null,tag_field);
return tag_field;
}
form.add_field("tags", array_field);

form.add_field("address", new ObjectField("Address"));
form.fields.address.add_field("house_number", new TextField("House Number",{type:"number"}));
form.fields.address.add_field("line_1", new TextField("Line 1"));
form.fields.address.add_field("line_2", new TextField("Line 2"));
form.fields.address.add_field("line_3", new TextField("Line 3"));

$("body").append(
form.element.append(
$("<button />").text("Submit")
),
output = $("<pre />")
)

form.on_submit(function(object){

var validator = new FieldVal(object);
var first_name = validator.get("first_name",BasicVal.string(true),BasicVal.min_length(5));
var last_name = validator.get("last_name",BasicVal.string(true),BasicVal.min_length(5));
var join_date = validator.get("join_date",BasicVal.string(true), DateVal.date(date_format, {
emit: DateVal.EMIT_DATE//emits the value as a Date object
}));
var gender = validator.get("gender",BasicVal.one_of(gender_choices));
var email = validator.get("email",BasicVal.string(true), BasicVal.email());
var bio = validator.get("bio",BasicVal.string(true));

var tags = validator.get("tags", BasicVal.array(true), BasicVal.min_length(1), BasicVal.each(function(value,i){
var error = BasicVal.string(true).check(value);
if(error){return error};
}));

var address = validator.get("address",BasicVal.object(true));
if(address){

var address_validator = new FieldVal(address);
address_validator.get("house_number", BasicVal.integer(true), BasicVal.minimum(10));
address_validator.get("line_1", BasicVal.string(true), BasicVal.min_length(5));
address_validator.get("line_2", BasicVal.string(true), BasicVal.min_length(5));
address_validator.get("line_3", BasicVal.string(true), BasicVal.min_length(5));
var address_error = address_validator.end();
if(address_error){
validator.invalid("address",address_error);
}
}

var error = validator.end();

if(error){
console.log(error);
form.error(error)
output.text('"error": '+JSON.stringify(error,null,4));
} else {
form.clear_errors();
output.text('"object": '+JSON.stringify(object,null,4));
}
})
})
</script>
Loading

0 comments on commit a32a13b

Please sign in to comment.