Merge pull request #676 from kinglozzer/urlsegmentfield-error-fix

Better error message when attempting to enter a blank URL Segment (fixes silverstripe/sapphire#1570)
This commit is contained in:
Ingo Schommer 2013-04-08 07:58:49 -07:00
commit d7435cde71
2 changed files with 20 additions and 4 deletions

View File

@ -43,7 +43,11 @@ class SiteTreeURLSegmentField extends TextField {
}
public function suggest($request) {
if(!$request->getVar('value')) return $this->httpError(405);
if(!$request->getVar('value')) {
return $this->httpError(405,
_t('SiteTreeURLSegmentField.EMPTY', 'Please enter a URL Segment or click cancel')
);
}
$page = $this->getPage();
// Same logic as SiteTree->onBeforeWrite

View File

@ -92,12 +92,24 @@
* @param (Function)
*/
suggest: function(val, callback) {
var field = this.find(':text'),
urlParts = $.path.parseUrl(this.closest('form').attr('action')),
var self = this,
field = self.find(':text'),
urlParts = $.path.parseUrl(self.closest('form').attr('action')),
url = urlParts.hrefNoSearch + '/field/' + field.attr('name') + '/suggest/?value=' + encodeURIComponent(val);
if(urlParts.search) url += '&' + urlParts.search.replace(/^\?/, '');
$.get(url, function(data) {callback.apply(this, arguments);});
$.ajax({
url: url,
success: function(data) {
callback.apply(this, arguments);
},
error: function(xhr, status) {
xhr.statusText = xhr.responseText;
},
complete: function() {
self.removeClass('loading');
}
});
}
});