vitmalina / w2ui

UI widgets for modern apps. Data table, forms, toolbars, sidebar, tabs, tooltips, popups. All under 120kb (gzipped).
http://w2ui.com
MIT License
2.67k stars 728 forks source link

Add methods to w2form prototype to allow extended it to support various data format #1712

Open hawkxu opened 7 years ago

hawkxu commented 7 years ago

I want to use W2UI with JSP pages with struts2 framework, the struts2 json plugin accept data format like this: {'username': 'test', 'password': 'secret'}, and W2UI library currently use format like: {'recid': 0, 'cmd': 'save-record', 'record': {'username': 'test', 'password': 'secret'}, ...}, so, I think about to add a method like

//build params in preparePostData method var params = obj.preparePostData(postData);

and before trigger after save event, add a method like data = obj.parseResponseData(data); // event after obj.trigger($.extend(eventData, { phase: 'after' }));

in additional, beacause the response data may be contains no status field, so check data.status not equal to error instead of equal to success if (data.status != 'error' && typeof callBack == 'function') callBack(data);

thanks and sorry for my poor English

mpf82 commented 7 years ago

You can already modify the postData before sending in the onSubmit event. You can also modify the received data before it is parsed in the onLoad event (you will have to modify the xhr object).

Please close the issue if this answers your question.

Cheers =)

hawkxu commented 7 years ago

I know about that I can do this through event handler, but I want to do some common process for all form, this need to extend from w2form (like w2obj.form.preparePostData = ....), and then do some special process for various form through event handler.

BTW: I'm building a library (taglib) to make JSP and W2UI integration a little easier, so I can not use event handler to solve my requirements.

thanks