question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What is for ? Copy form data (JSON/POST)

See original GitHub issue

Hi @brookhong,

First of all, thx you very much for this awesome extension !

Not a issue here, but I just curious how can I and for what using the copy form data yp , yf functionalities ? How can I use the JSON copied in clipboard ? I’m sure it’s very useful so I ask the question ! 😃

Best regards. Mike

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
brookhongcommented, May 11, 2019

Maybe caused by the selector in element.querySelectorAll('input[type=text]'), I tried on https://addons.mozilla.org/en-US/firefox/users/edit with below snippet, it works.

function generateFormKey(form) {
    return (form.method || "get") + "::" + new URL(form.action).pathname;
}
mapkey('yf', '#7Copy form data in JSON on current page', function() {
    var fd = {};
    document.querySelectorAll('form').forEach(function(form) {
        fd[generateFormKey(form)] = getFormData(form, "json");
    });
    Clipboard.write(JSON.stringify(fd, null, 4));
});
mapkey(';pf', '#7Fill form with data from yf', function() {
    Hints.create('form', function(element, event) {
        var formKey = generateFormKey(element);
        Clipboard.read(function(response) {
            var forms = JSON.parse(response.data.trim());
            if (forms.hasOwnProperty(formKey)) {
                var fd = forms[formKey];
                element.querySelectorAll('input').forEach(function(ip) {
                    if (fd.hasOwnProperty(ip.name) && typeof(fd[ip.name]) !== "object") {
                        ip.value = fd[ip.name];
                    }
                });
            } else {
                Front.showBanner("No form data found for your selection from clipboard.");
            }
        });
    });
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send a JSON object using html form data
Get complete form data as array and json stringify it. var formData = JSON.stringify($("#myForm").serializeArray());. You can use it later in ajax.
Read more >
POST form-data file upload + JSON - YouTube
Postman allows you to submit a form - data request where in one key you send a file and in the other key...
Read more >
POST Form Data as JSON with Fetch API in JavaScript
Use JavaScript to convert HTML form data to JSON & submit to server... Professional JavaScript Course: ...
Read more >
How to use fetch to POST form data as JSON to your API
How to use fetch to POST form data as JSON to your API · Step 1. Listen for when a user submits the...
Read more >
How to Convert HTML Form Field Values to a JSON Object
The FormData API doesn't directly convert form values to JSON, but we can get there by using the entries method and passing its...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found