mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-14 21:46:27 +02:00
e46a8b8a13
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@93693 467b73ca-7a2a-4603-9d3b-597d59a354a9
39 lines
895 B
JavaScript
Executable File
39 lines
895 B
JavaScript
Executable File
UniqueFormField = Class.create();
|
|
UniqueFormField.prototype = {
|
|
validate: function() {
|
|
// check that the value is not in use, and matches the pattern
|
|
var suggested = this.value;
|
|
|
|
if( this.restrictedValues[suggested] || suggested == null ) {
|
|
suggested = this.suggestNewValue();
|
|
statusMessage(ss.i18n.sprintf(
|
|
ss.i18n._t('UNIQUEFIELD.SUGGESTED', "Changed value to '%s' : %s"),
|
|
suggested,
|
|
this.restrictedMessage
|
|
));
|
|
this.value = suggested;
|
|
}
|
|
},
|
|
suggestNewValue: function() {
|
|
var parts = this.value.match( /(.*)(\d+)$/ );
|
|
var prefix = '';
|
|
var count = 1;
|
|
|
|
|
|
if( parts )
|
|
prefix = parts[1];
|
|
else
|
|
prefix = this.value;
|
|
|
|
if( prefix.charAt(prefix.length-1) != ' ' )
|
|
prefix = prefix + ' ';
|
|
|
|
var suggested = prefix + count;
|
|
|
|
while( this.restrictedValues[suggested] )
|
|
suggested = prefix + (++count);
|
|
|
|
return suggested;
|
|
}
|
|
}
|