Better error message when attempting to enter a blank URL Segment (fixes silverstripe/silverstripe-cms#1570)

This commit is contained in:
Loz Calver 2013-04-05 14:06:32 +01:00
parent 6457ab2433
commit ea446f2ade
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');
}
});
}
});