tonytomov / jqGrid

jQuery grid plugin
www.trirand.com
2.84k stars 1.2k forks source link

Possible bug in processing custom-element fields in an edit form #1018

Open unle70 opened 1 year ago

unle70 commented 1 year ago

Hi Tony,

I'm having some trouble with implementing a Custom Element and going through the jqGrid code I see something strange. Perhaps you can help to clarify whether this is a problem or not.

I'm trying to implement an HTML5 input with datalist. You even have a nice article written on this topic. But my element needs to work somewhat like a "select", returning a "key" instead of the actual value in the input. This means that the custom-value function is critical for reading the correct value out of this field.

When creating a Custom Element in form-edit mode, the HTML structure looks like this:

<td class="DataTD">
    <span class="FormElement">
        <input class="FormElement customelement">    <!-- This is added by my custom-element function -->
    </span>
</td>

As you can see, both the "span" and the "input" have the "FormElement" class. Now my problem is in the "getFormData()" function of jqGrid (see below).

In line #11467 we pull out all the items with ".FormElement". This would include both the "span" AND the "input". Then in line #11468 we pull out all the items with ".customelement" INSIDE the ".FormElement". When we do that for the "span", we get the "input" which is inside. But when we do that for the "input" itself, we get an EMPTY list!

Now the problem is that in line #11469 we check if the list is empty and if it is, we try to read the item as a "non-custom". Eventually we reach line #11508 and then just read the simple value out of the "input". In my case, I see the custom-value function IS being called once and IS returning the correct data, but eventually jqGrid is sending the raw value of the input item to the server. Since we are reading the value for the same "name" twice, the later will override the former. Eventually the value received from the custom-value function will be overridden.

Is this a bug?

https://github.com/tonytomov/jqGrid/blob/a00419ffaced1f62fef16e09c0d4c6e28509c987/js/jquery.jqGrid.js#L11465-L11509

unle70 commented 1 year ago

Just a small update: As I mentioned above, I saw the reference article (below) as for how such a custom element should be constructed. In that article it said that the "input" element should have a "FormElement" class. Now I tried to remove this class from the "input" element so that only the "span" would still have it. Looks like it works better.

https://guriddo.net/?kbe_knowledgebase=using-datalist-drop-down-menu-in-form-edit

tonytomov commented 1 year ago

I'm just going to ask - you why you set the input with this class? I will go to read the article.

Thanks anyway.

tonytomov commented 1 year ago

Thanks Udi,

This was definitely wrong setting in the input. The reason that it was set wrong was to preserve the css style for the input missing that it not should be set.

I have fixed both the code and the article.

Thank you very much again.

Tony.