Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use clone withDataAndEvents for form values #117

Conversation

Subtletree
Copy link
Contributor

@Subtletree Subtletree commented Jun 30, 2017

This PR is just to start a conversation about 2 features and possibly merge in the future.

It does 2 things:

  1. Exports printThis as an AMD module:
 ;(function(factory) {
    'use strict';
    if (typeof define === 'function' && define.amd) {
        define(['jquery'], factory);
    } else if (jQuery && !jQuery.fn.printThis) {
        factory(jQuery);
    }
})(function($) {
  1. Uses clone(true) to copy form values instead of manually iterating over inputs/selects.
    This should cover more scenarios. e.g In my situation some inputs don't have a name attribute so values weren't being copied.

This takes care of an item on the to do list 'Look at more efficient form field value persist'

I haven't tested every use case but am using this branch personally with success.

@Subtletree Subtletree changed the title Use clone with data and events for form values Use clone withDataAndEvents for form values Jun 30, 2017
@oculus42
Copy link
Collaborator

oculus42 commented Jul 29, 2017

.clone(true) doesn't persist <select> values. I tested against jQuery 1.9.x, 2.2.x, and 3.x.
We would need to keep at least the select logic. I haven't tested all form types, but select is likely the problem child.

JSFiddle testing .clone(true) support

@oculus42
Copy link
Collaborator

To be clear, I think this is a good idea; even if we have the special case for <select>, it's shrinks the library with the same result.

@Subtletree
Copy link
Contributor Author

Oh good catch. Realised I was testing this with a select library that didn't actually use a select element.

I've submitted #120 with just the form value part of this PR.
Will open a separate one for the module part

@Subtletree Subtletree closed this Jul 30, 2017
@Subtletree
Copy link
Contributor Author

PR #121 addresses exporting

@Subtletree Subtletree deleted the use-clone-withDataAndEvents-for-form-values branch August 27, 2018 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants