Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Custom Input: Form Editing - Value not added to postdata sent to server
18/11/2009
09:34
Avatar
Basdub
Member
Members
Forum Posts: 24
Member Since:
19/05/2009
sp_UserOfflineSmall Offline

Tony,

Just to have this as a seperate topic. The value from the custom input field is not sent to the server. The fix is very easy and might apply also for inline editing.

In file grid.formedit.js around line 543. you will find the following:

if($(this).hasClass(”customelement”))

In that situation, $(this) is in fact the container of the input element => <span class=”FormElement”><input…

Therefore it will never have the class customElement.

Solution:

Change

$(this)

to

$(this).children(”input”)[0]

PS: There might be a better way to get the child control. Would like to learn it!

18/11/2009
09:40
Avatar
Basdub
Member
Members
Forum Posts: 24
Member Since:
19/05/2009
sp_UserOfflineSmall Offline

That's not a good fix.

Maybe the "customelement" class should be set on the span element

18/11/2009
14:10
Avatar
Basdub
Member
Members
Forum Posts: 24
Member Since:
19/05/2009
sp_UserOfflineSmall Offline

Ok, i got it to work. Assuming we want to keep the span surrounding the customelement.... which i think is good!

In grid.formedit.js around line 543

Replace

if($(this).hasClass("customelement")) {
     var nm = this.name, elem = this;

With

if($(this)[0].tagName === 'SPAN' && $(this).children("input").hasClass("customelement")) {
      var nm = $(this).children("input")[0].name, elem = $(this).children("input")[0];

Also, in the same area of the code inside the "try" there's an undefined cm. Replacing "cm" with "this" fix the issue.

All of this might need to be applied in the grid.inline.js too.

If I have time, I might send Tony a push request for this.

18/11/2009
14:20
Avatar
Basdub
Member
Members
Forum Posts: 24
Member Since:
19/05/2009
sp_UserOfflineSmall Offline

If someone wants to have a custom element with multiple input or whatever, this might not work properly.  I would recommend setting the customelement class "flag" on the span element.

This could eventually allow the custom element to send an additional set of itemSSS that could extend the current postdata

So instead of having

postdata[nm] = this.editoptions.custom_value($("#"+nm,"#"+frmtb),'get');

We could have

p = this.editoptions.custom_value($("#"+nm,"#"+frmtb),'get');
$.extend(true,{},postdata,p);

Just a thoughtWink

18/11/2009
15:33
Avatar
markw65
Member
Members
Forum Posts: 179
Member Since:
30/07/2009
sp_UserOfflineSmall Offline

Basdub said:

if($(this)[0].tagName === 'SPAN' && $(this).children(”input”).hasClass(”customelement”)) {
      var nm = $(this).children(”input”)[0].name, elem = $(this).children(”input”)[0];

But why does a customelement have to be an input? Why couldnt I use a textarea, or a select, or something of my own devising (eg, a fixed datepicker, not associated with an input).

Shouldnt it be something like:

var celm = $(".customelement", this);

if (celm.length) {

   var elem = celm[0], nm = elem.name;

   ...

}

Mark

18/11/2009
16:10
Avatar
Basdub
Member
Members
Forum Posts: 24
Member Since:
19/05/2009
sp_UserOfflineSmall Offline

Mark, that was just a quick fix. I totally agree with you on the fact that the custom element could be whatever we want, even further, it could be more than one control. See post 4!

I said in the post 4 that i would recommend to simply put the ".customelement" class flag on the <span> tag that surrounds the custom control.

Maybe the span should be sent to the custom_value on a "get". Then, you can work with whatever is inside that span and return the appropriate value.

All in all, that was a good catch from you. The "input" is way to much strict.

Regards,

19/11/2009
04:39
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Basdub,

I think that Mark is right. We should not be limited to input elements only, but to have a freedom to put what we want (this is the primary goal of the custom elements - otherwiese you can use the standart input and do evrething what you want with him)

I have put the fix provided from Mark and tested it and it seems to work. Beside from this there was another copy paste problem Smile

The fix is in GitHub. Will be happy if it will work for you too.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

19/11/2009
08:20
Avatar
Basdub
Member
Members
Forum Posts: 24
Member Since:
19/05/2009
sp_UserOfflineSmall Offline

Ok, how can i say this again: I AGREE WITH BOTH OF YOU!!!!

I'm just saying that the provided solution could be made EVEN MORE FLEXIBLE, as stated in POST 4 and in POST 6,  by setting the customelement class on the SPAN element and send the ENTIRE SPAN to custom_value function.

That way someone could even make ajax call to create MORE THAN ONE INPUT, SELECT, … element inside one custom_element. For example, someone could have another jGrid with mutiselect enabled as a custom element.

19/11/2009
09:24
Avatar
markw65
Member
Members
Forum Posts: 179
Member Since:
30/07/2009
sp_UserOfflineSmall Offline

Hi Tony,

I think you have a typo in your fix:

var nm = elem.name, elem = celm[0];

you need to set elem, before name. Also, having set elem, you could use it, rather than calling
$("#"+nm,"#"+frmtb) again (or drop elem altogether, and use nm=celm[0].name).

On basdub's idea for multiple inputs - I'm missing the point. Each customelement is associated with a single cell in the grid, so why would you want to post multiple values to the server?

I can see how you could want eg a datepicker and timepicker for a cell that contained a date-time. But you can do that anyway - and its still only a single value going to the server.

More generally, you /receive/ the data for the cell as a single item, why not post it back the same way? And if you do need multiple values, you can use json encoding (or any other encoding you like) to pack them into the one field...

And finally (!) I think the custom_value function should be passed the same element that custom_element created (as it does now) - if it wants multiple inputs wrapped in a span, it can create its own span 🙂

Mark

19/11/2009
09:31
Avatar
Basdub
Member
Members
Forum Posts: 24
Member Since:
19/05/2009
sp_UserOfflineSmall Offline

Good explanation Mark, thank you!

I guess yes in one scenario, one could wrap everything inside it's own span.

Good for me! I'll take that!

Thanks again

Regards,

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
93 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information