Merge pull request #285 from ryanwachtl/bug-8032-multiple-urlsegment-fields

Prevent conflict when using more than one SiteTreeURLSegmentField in a CMS edit form
This commit is contained in:
Ingo Schommer 2013-02-04 14:54:41 -08:00
commit fbfc939fc4

View File

@ -27,20 +27,19 @@
self.data('OrigVal', self.val()); self.data('OrigVal', self.val());
var form = self.parents('form'); var form = self.closest('form');
var url_segment = $('.field.urlsegment', form).find(':text'); var urlSegmentInput = $('input:text[name=URLSegment]', form);
var live_link = $('input[name=LiveLink]', form); var liveLinkInput = $('input[name=LiveLink]', form);
if (urlSegmentInput.length > 0) {
self._addActions(); self._addActions();
if(url_segment.length > 0) {
this.bind('change', function(e) { this.bind('change', function(e) {
var origTitle = self.data('OrigVal'); var origTitle = self.data('OrigVal');
var title = self.val(); var title = self.val();
self.data('OrigVal', title); self.data('OrigVal', title);
// Criteria for defining a "new" page // Criteria for defining a "new" page
if ((url_segment.val().indexOf('new') == 0) && live_link.val() == '') { if ((urlSegmentInput.val().indexOf('new') == 0) && liveLinkInput.val() == '') {
self.updateURLSegment(title); self.updateURLSegment(title);
} else { } else {
$('.update', self.parent()).show(); $('.update', self.parent()).show();
@ -83,9 +82,10 @@
* (String) title * (String) title
*/ */
updateURLSegment: function(title) { updateURLSegment: function(title) {
var url_segment_field = $('.field.urlsegment', this.parents('form')); var urlSegmentInput = $('input:text[name=URLSegment]', this.closest('form'));
var urlSegmentField = urlSegmentInput.closest('.field.urlsegment');
var updateURLFromTitle = $('.update', this.parent()); var updateURLFromTitle = $('.update', this.parent());
url_segment_field.update(title); urlSegmentField.update(title);
if (updateURLFromTitle.is(':visible')) { if (updateURLFromTitle.is(':visible')) {
updateURLFromTitle.hide(); updateURLFromTitle.hide();
} }