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

TextArea for formData #587

Closed
kongres opened this issue Dec 22, 2015 · 3 comments
Closed

TextArea for formData #587

kongres opened this issue Dec 22, 2015 · 3 comments

Comments

@kongres
Copy link

kongres commented Dec 22, 2015

I want to have textarea for one of my parameters which accept JSON model.
Please note I use multipart/form-data for my request.
My definition is

            operation.parameters.Add(new Parameter
            {
                name = "file",
                required = true,
                type = "file",
                @in = "formData",
                description = "File with following formats: pdf, png, jpg, bmp."
            });

            operation.parameters.Add(new Parameter
            {
                name = "data",
                required = false,
                @in = "formData",
                type = "object",
                schema = new Schema() { @ref = "#/definitions/SomeModel", type = "object"},
                description = "Desciption",

            });

And what I have on UI:
image

I want to show textarea for 'data' parameter instead of input. I've tried a lot of different ways but unsuccessfuly. Is it possible? How?

@HarelM
Copy link

HarelM commented Jul 30, 2016

No sure if this is still relevant, but for other people to use in the future the following code does it:
setting @in = "body" fixes it.

operation.parameters.Add(new Parameter
            {
                name = "data",
                required = false,
                @in = "body",
                type = "object",
                schema = new Schema() { @ref = "#/definitions/SomeModel", type = "object"},
                description = "Desciption",

            });

@g2petter
Copy link

g2petter commented Jun 2, 2017

I might be coming at this from a wrong angle, but it seems to me like the fix suggested by @HarelM doesn't work. By adding the one parameter as body when you still have one or more other parameters as formData is against the spec, ref. this discussion: swagger-api/swagger-editor#889

Since form parameters are sent in the payload, they cannot be declared together with a body parameter for the same operation.

So I guess @kongres' question remains: how can you have a formData parameter use a textarea that behaves like a body textarea?

@justinhorner
Copy link

Very old, but just in case anyone else stumbles across this problem, I used Javascript injection to 'fix' this.

// get the input element by name (or another unique attribute)
let _input = $('input[name="uniqueName"]');

var $txtArea = $('<textarea />');
// set/re-set desired attributes
$txtArea.attr('class', _input.attr('class'));
$txtArea.attr('name',  _input.attr('name'));
$txtArea.attr('placeholder',  _input.attr('placeholder'));
$txtArea.attr('id',  _input.attr('id'));
$txtArea.val(_input.value);

// replace
_input.replaceWith($txtArea);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants