mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
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:
commit
d7435cde71
@ -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
|
||||
|
@ -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');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user