Skip to content

Commit d39beba

Browse files
committed
Editable: Do NOT create a FORM element when editing. Since W3C DTD forbids nested FORMs, Editable could potentially limit users from using it inside of another user FORM.
1 parent a5f417e commit d39beba

File tree

2 files changed

+25
-36
lines changed

2 files changed

+25
-36
lines changed

themes/base/jquery.ui.editable.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* http://docs.jquery.com/UI/Tooltip#theming
99
*/
1010
.ui-editable .ui-widget-content.ui-state-default {background: none !important;}
11-
.ui-editable-form { position: relative; overflow: hidden; padding: 0; vertical-align: middle; z-index: 2; }
11+
.ui-editable-edit-area { position: relative; overflow: hidden; padding: 0; vertical-align: middle; z-index: 2; }
1212
.ui-editable-input-area { padding: 0.4em; }
1313
.ui-editable-placeholder { color: #555; font-style: italic; }
1414
.ui-editable-input { border: none; display: block; padding: 0; margin: 0;

ui/jquery.ui.editable.js

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
(function( $, undefined ) {
1717

1818
var editableClass = "ui-editable ui-widget",
19-
formClass = "ui-editable-form",
19+
editAreaClass = "ui-editable-edit-area",
2020
buttonClass = "ui-editable-button",
2121
buttonsAreaClass = "ui-editable-buttons-area",
2222
cancelClass = "ui-editable-cancel",
@@ -49,7 +49,7 @@ $.widget( "ui.editable", {
4949
},
5050

5151
save: function() {
52-
$( "form", this.element ).submit();
52+
this._save();
5353
},
5454

5555
cancel: function() {
@@ -105,7 +105,7 @@ $.widget( "ui.editable", {
105105

106106
if ( !this._editing ) {}
107107
else if ( $this.hasClass( saveClass ) || $this.parent().hasClass( saveClass ) ) {
108-
this.save();
108+
this._save();
109109
return false;
110110
}
111111
else if ( $this.hasClass( cancelClass ) || $this.parent().hasClass( cancelClass ) ) {
@@ -128,7 +128,7 @@ $.widget( "ui.editable", {
128128
if(this._skipEnterSubmit) {
129129
break;
130130
}
131-
this.save();
131+
this._save();
132132
return false;
133133
case keyCode.ESCAPE:
134134
this._cancel();
@@ -159,9 +159,9 @@ $.widget( "ui.editable", {
159159
// Create a new stacking context on element by setting its z-index from auto to 0.
160160
this.element.css( "z-index", 0 );
161161
}
162-
this.element.html( this._form() );
162+
this.element.html( this._drawEdit() );
163+
this._editor.bind( this );
163164
this._adjustInputWidth();
164-
this._formEvents();
165165
},
166166

167167
_placeholder: function() {
@@ -170,21 +170,21 @@ $.widget( "ui.editable", {
170170
.html( this.options.placeholder );
171171
},
172172

173-
_form: function() {
174-
var form = $( "<form></form>" ).addClass( formClass );
175-
this.frame = form;
173+
_drawEdit: function() {
174+
var editArea = $( "<div></div>" ).addClass( editAreaClass );
175+
this.frame = editArea;
176176
this._hoverable( this.frame.addClass( hoverableClass ) );
177177
$( "<div></div>" )
178178
.addClass( inputAreaClass )
179179
.append( this._editor.element( this ) )
180-
.appendTo( form );
180+
.appendTo( editArea );
181181
if( this.options.buttons ) {
182-
this._drawButtons().appendTo( form );
182+
this._drawButtons().appendTo( editArea );
183183
}
184-
return form;
184+
return editArea;
185185
},
186186

187-
_drawButtons: function( form ) {
187+
_drawButtons: function() {
188188
var i, buttons = {}, ordered_buttons = $([]),
189189
buttonsArea = $( "<div></div>" ).addClass( buttonsAreaClass );
190190
for( i in this.options.buttons ) {
@@ -242,26 +242,15 @@ $.widget( "ui.editable", {
242242
$( "." + inputAreaClass, this.frame ).css( margin );
243243
},
244244

245-
_formEvents: function() {
246-
var self = this;
247-
$( "form", this.element )
248-
.submit( function( event ) {
249-
self._save.call( self, event, self._editor.value( self, this ) );
250-
return false;
251-
});
252-
this._editor.bind( this );
253-
},
254-
255-
_save: function( event, newValue ) {
256-
var hash = {
257-
value: newValue
258-
};
245+
_save: function() {
246+
var newValue = this._editor.value( this ),
247+
hash = { value: newValue };
259248

260-
if ( this._trigger( "save", event, hash ) === false ) {
249+
if ( this._trigger( "save", null, hash ) === false ) {
261250
return;
262251
}
263252
if ( this.value() !== newValue ) {
264-
if ( this._trigger( "change", event, hash ) === false ) {
253+
if ( this._trigger( "change", null, hash ) === false ) {
265254
return;
266255
}
267256
this.value( newValue );
@@ -301,8 +290,8 @@ $.ui.editable.editors = {
301290
})
302291
.focus();
303292
},
304-
value: function( editable, form ) {
305-
return $( "input", form ).val();
293+
value: function( editable ) {
294+
return $( "input", editable.element ).val();
306295
}
307296
},
308297
textarea: {
@@ -324,8 +313,8 @@ $.ui.editable.editors = {
324313
})
325314
.focus();
326315
},
327-
value: function( editable, form ) {
328-
return $( "textarea", form ).val().replace(/\r\n|\r|\n/g, "<br/>");
316+
value: function( editable ) {
317+
return $( "textarea", editable.element ).val().replace(/\r\n|\r|\n/g, "<br/>");
329318
}
330319
},
331320
select: $.noop,
@@ -338,8 +327,8 @@ $.ui.editable.editors = {
338327
$( "input", editable.element ).datepicker( editable._editorOptions );
339328
$.ui.editable.editors.text.bind( editable );
340329
},
341-
value: function( editable, form ) {
342-
return $.ui.editable.editors.text.value( editable, form );
330+
value: function( editable ) {
331+
return $.ui.editable.editors.text.value( editable );
343332
}
344333
}
345334
};

0 commit comments

Comments
 (0)