jquery-datalink icon indicating copy to clipboard operation
jquery-datalink copied to clipboard

jQuery 1.5 breaks support for fields with '.' in name

Open ntziolis opened this issue 14 years ago • 2 comments

The current version is not able to link from object to form fields, when using a '.' in a field name as ASP.NET MVC does by default when having hierarchical data in a form (when using the EditorFor<> helpers for model properties).

$(data).setField("Name", "SomeNewValue"); <- works (in first level of hierarchy, so no '.'
$(data).setField("English_Name", "SomeNewValue"); <- works (uses the id)
$(data).setField("English.Name", "SomeNewValue"); <-does not work (should use the name)

Thats the commit: https://github.com/jquery/jquery-datalink/commit/f2b13ff52fdf728097fdff65f206fad9882d7aa9

ntziolis avatar Feb 01 '11 13:02 ntziolis

I have also noticed this behavior. I am using Spring MVC and also need to have the model mapped using dot notation. I have been trying to figure out a fix for this but have been unsuccessful as of yet. Leaning toward implementing my own solution.

D1g1talEntr0py avatar Sep 13 '11 14:09 D1g1talEntr0py

I was able to modify the setField function to fix this behavior. The block of code that handles updating the backing object would split the name on a '.' character. I think it has something to do with name-spacing for the event handler. If the code is modified to remove this, it works perfectly fine. This will, of course, break the initial design, but I for one will never need to code to behave how it was originally designed. Here is the code;

This

var parts = field.split('.');
parts[1] = parts[1] ? '.' + parts[1] : '';
    
var $this = $(target),
args = [ parts[0], value ];
    
$this.triggerHandler(eventNameSetField + parts[1] + '!', args);
if (value !== undefined) {
    target[ field ] = value;
}
$this.triggerHandler(eventNameChangeField + parts[1] + '!', args);

becomes this...

var $this = $(target),
args = [field, value];

$this.triggerHandler(eventNameSetField + '!', args);
if (value !== undefined) {
    target[field] = value;
}
$this.triggerHandler(eventNameChangeField + '!', args);

D1g1talEntr0py avatar Sep 25 '11 13:09 D1g1talEntr0py