Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
origin-web-common
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Java-于龙
origin-web-common
Commits
d02f13c4
Commit
d02f13c4
authored
Apr 28, 2017
by
Sam Padgett
Committed by
GitHub
Apr 28, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #53 from dtaylor113/master
Added osc-unique directive
parents
e358899c
1d1294a9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
176 additions
and
1 deletions
+176
-1
origin-web-common-ui.js
dist/origin-web-common-ui.js
+53
-0
origin-web-common.js
dist/origin-web-common.js
+53
-0
origin-web-common.min.js
dist/origin-web-common.min.js
+17
-1
oscUnique.js
src/components/osc-unique/oscUnique.js
+53
-0
No files found.
dist/origin-web-common-ui.js
View file @
d02f13c4
...
...
@@ -575,6 +575,59 @@ angular.module("openshiftCommonUI")
};
});
;
'use strict'
;
// oscUnique is a validation directive
// use:
// Put it on an input or other DOM node with an ng-model attribute.
// Pass a list (array, or object) via osc-unique="list"
//
// Sets model $valid true||false
// - model is valid so long as the item is not already in the list
//
// Key off $valid to enable/disable/sow/etc other objects
//
// Validates that the ng-model is unique in a list of values.
// ng-model: 'foo'
// oscUnique: ['foo', 'bar', 'baz'] // false, the string 'foo' is in the list
// oscUnique: [1,2,4] // true, the string 'foo' is not in the list
// oscUnique: {foo: true, bar: false} // false, the object has key 'foo'
// NOTES:
// - non-array values passed to oscUnqiue will be transformed into an array.
// - oscUnqiue: 'foo' => [0,1,2] (probably not what you want, so don't pass a string)
// - objects passed will be converted to a list of object keys.
// - { foo: false } would still be invalid, because the key exists (value is ignored)
// - recommended to pass an array
//
// Example:
// - prevent a button from being clickable if the input value has already been used
// <input ng-model="key" osc-unique="keys" />
// <button ng-disabled="form.key.$error.oscUnique" ng-click="submit()">Submit</button>
//
angular
.
module
(
'openshiftCommonUI'
)
.
directive
(
'oscUnique'
,
function
()
{
return
{
restrict
:
'A'
,
scope
:
{
oscUnique
:
'='
},
require
:
'ngModel'
,
link
:
function
(
$scope
,
$elem
,
$attrs
,
ctrl
)
{
var
list
=
[];
$scope
.
$watchCollection
(
'oscUnique'
,
function
(
newVal
)
{
list
=
_
.
isArray
(
newVal
)
?
newVal
:
_
.
keys
(
newVal
);
});
ctrl
.
$parsers
.
unshift
(
function
(
value
)
{
// is valid so long as it doesn't already exist
ctrl
.
$setValidity
(
'oscUnique'
,
!
_
.
includes
(
list
,
value
));
return
value
;
});
}
};
});
;
'use strict'
;
angular
.
module
(
'openshiftCommonUI'
)
// The HTML5 `autofocus` attribute does not work reliably with Angular,
...
...
dist/origin-web-common.js
View file @
d02f13c4
...
...
@@ -746,6 +746,59 @@ angular.module("openshiftCommonUI")
};
}]);
;
'use strict'
;
// oscUnique is a validation directive
// use:
// Put it on an input or other DOM node with an ng-model attribute.
// Pass a list (array, or object) via osc-unique="list"
//
// Sets model $valid true||false
// - model is valid so long as the item is not already in the list
//
// Key off $valid to enable/disable/sow/etc other objects
//
// Validates that the ng-model is unique in a list of values.
// ng-model: 'foo'
// oscUnique: ['foo', 'bar', 'baz'] // false, the string 'foo' is in the list
// oscUnique: [1,2,4] // true, the string 'foo' is not in the list
// oscUnique: {foo: true, bar: false} // false, the object has key 'foo'
// NOTES:
// - non-array values passed to oscUnqiue will be transformed into an array.
// - oscUnqiue: 'foo' => [0,1,2] (probably not what you want, so don't pass a string)
// - objects passed will be converted to a list of object keys.
// - { foo: false } would still be invalid, because the key exists (value is ignored)
// - recommended to pass an array
//
// Example:
// - prevent a button from being clickable if the input value has already been used
// <input ng-model="key" osc-unique="keys" />
// <button ng-disabled="form.key.$error.oscUnique" ng-click="submit()">Submit</button>
//
angular
.
module
(
'openshiftCommonUI'
)
.
directive
(
'oscUnique'
,
function
()
{
return
{
restrict
:
'A'
,
scope
:
{
oscUnique
:
'='
},
require
:
'ngModel'
,
link
:
function
(
$scope
,
$elem
,
$attrs
,
ctrl
)
{
var
list
=
[];
$scope
.
$watchCollection
(
'oscUnique'
,
function
(
newVal
)
{
list
=
_
.
isArray
(
newVal
)
?
newVal
:
_
.
keys
(
newVal
);
});
ctrl
.
$parsers
.
unshift
(
function
(
value
)
{
// is valid so long as it doesn't already exist
ctrl
.
$setValidity
(
'oscUnique'
,
!
_
.
includes
(
list
,
value
));
return
value
;
});
}
};
});
;
'use strict'
;
angular
.
module
(
'openshiftCommonUI'
)
// The HTML5 `autofocus` attribute does not work reliably with Angular,
...
...
dist/origin-web-common.min.js
View file @
d02f13c4
...
...
@@ -252,7 +252,23 @@ cb ? cb() :$window.history.back();
};
}
]
};
}
]),
angular
.
module
(
"openshiftCommonUI"
).
directive
(
"takeFocus"
,
[
"$timeout"
,
function
(
$timeout
)
{
}
]),
angular
.
module
(
"openshiftCommonUI"
).
directive
(
"oscUnique"
,
function
()
{
return
{
restrict
:
"A"
,
scope
:{
oscUnique
:
"="
},
require
:
"ngModel"
,
link
:
function
(
$scope
,
$elem
,
$attrs
,
ctrl
)
{
var
list
=
[];
$scope
.
$watchCollection
(
"oscUnique"
,
function
(
newVal
)
{
list
=
_
.
isArray
(
newVal
)
?
newVal
:
_
.
keys
(
newVal
);
}),
ctrl
.
$parsers
.
unshift
(
function
(
value
)
{
return
ctrl
.
$setValidity
(
"oscUnique"
,
!
_
.
includes
(
list
,
value
)),
value
;
});
}
};
}),
angular
.
module
(
"openshiftCommonUI"
).
directive
(
"takeFocus"
,
[
"$timeout"
,
function
(
$timeout
)
{
return
{
restrict
:
"A"
,
link
:
function
(
scope
,
element
)
{
...
...
src/components/osc-unique/oscUnique.js
0 → 100644
View file @
d02f13c4
'use strict'
;
// oscUnique is a validation directive
// use:
// Put it on an input or other DOM node with an ng-model attribute.
// Pass a list (array, or object) via osc-unique="list"
//
// Sets model $valid true||false
// - model is valid so long as the item is not already in the list
//
// Key off $valid to enable/disable/sow/etc other objects
//
// Validates that the ng-model is unique in a list of values.
// ng-model: 'foo'
// oscUnique: ['foo', 'bar', 'baz'] // false, the string 'foo' is in the list
// oscUnique: [1,2,4] // true, the string 'foo' is not in the list
// oscUnique: {foo: true, bar: false} // false, the object has key 'foo'
// NOTES:
// - non-array values passed to oscUnqiue will be transformed into an array.
// - oscUnqiue: 'foo' => [0,1,2] (probably not what you want, so don't pass a string)
// - objects passed will be converted to a list of object keys.
// - { foo: false } would still be invalid, because the key exists (value is ignored)
// - recommended to pass an array
//
// Example:
// - prevent a button from being clickable if the input value has already been used
// <input ng-model="key" osc-unique="keys" />
// <button ng-disabled="form.key.$error.oscUnique" ng-click="submit()">Submit</button>
//
angular
.
module
(
'openshiftCommonUI'
)
.
directive
(
'oscUnique'
,
function
()
{
return
{
restrict
:
'A'
,
scope
:
{
oscUnique
:
'='
},
require
:
'ngModel'
,
link
:
function
(
$scope
,
$elem
,
$attrs
,
ctrl
)
{
var
list
=
[];
$scope
.
$watchCollection
(
'oscUnique'
,
function
(
newVal
)
{
list
=
_
.
isArray
(
newVal
)
?
newVal
:
_
.
keys
(
newVal
);
});
ctrl
.
$parsers
.
unshift
(
function
(
value
)
{
// is valid so long as it doesn't already exist
ctrl
.
$setValidity
(
'oscUnique'
,
!
_
.
includes
(
list
,
value
));
return
value
;
});
}
};
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment