Hello everyone! I have 1 suitelet form with inline...
# suitescript
j
Hello everyone! I have 1 suitelet form with inlinehtml. In the inlinehtml, i have 2 post forms with separate submit buttons. When hitting the submit, I was only able to get the value of the 1st submit button regardless if I click the 2nd submit button. Is this somehow a NS limitation when handling HTML forms? Am I only allowed to use 1 form in the inlinehtml?
e
You can have multiple forms on a page, so we'll probably need more details about your implementation
j
Here's a snippet of the HTML Inline:
Copy code
<div class="container-fluid" style="">
        <!-- Buttons -->
        <div class="row">
            <div class="col-sm">
                <nav class="navbar navbar-dark bg-dark">
                    <form action="" enctype="multipart/form-data" method="POST" class="form-inline">
                        <div class="form-group row" style="padding: 20px">
                            <input class="form-control col-sm-6" type="search" name="workordername" placeholder="${strWorkOrderName}" aria-label="Search" />
                            <div class="col-sm-1"></div>
                            <input class="form-control text-start" type="text" name="action" id="search_action" value="search" hidden>
                            <button class="btn btn-outline-light col-sm-4" type="submit">
                                Search
                            </button>
                        </div>
                        <div class="form-group row" style="padding: 20px">
                            <input class="form-control text-start" type="text" name="action" id="clear_action" value="clear" hidden>
                            <button class="btn btn-outline-light" type="submit">
                                Clear
                            </button>
                        </div>
                    </form>
                </nav>
            </div>
        </div>
Suitelet:
Copy code
const onRequest = (scriptContext) => {
    try {
      log.audit({ title: "Method", details: scriptContext.request.method });
      let objParams = scriptContext.request.parameters;
      log.audit({ title: "objParams", details: { objParams } });
      if (scriptContext.request.method === "GET") {
        //
      } else {
        let strAction = objParams.action;
      }
    } catch (e) {
      log.error({ title: "Error", details: JSON.stringify(e) });
    }
  };
From here, strAction will always be of value "search" regardless if I clicked the "Clear" submit button. Adding value="clear" or value="search" on the button sharing the same name="action", still gets the value of the first name="action"
e
The Suitelet itself is a
form
, so I'm guessing you're seeing this behavior because you have nested `form`s. You can try giving your `form`s an
id
, then adding the
form
attribute to your `button`s.
Copy code
<form id='form1'>
  <button form='form1'>
👀 1
j
Will give it a try! 🙂 Thank you
e
If that doesn't work, then I suggest changing the buttons to a different
type
and submitting the forms "manually" in the button click handlers
Since nested forms aren't technically valid HTML, you might have to do some workarounds like that
j
Hi Eric, adding form id and button id works, except that the first form is being considered as the suitelet form itself. So I added a placeholder for the suitelet form with empty value and rest of my form works correctly! Thank you!
✅ 1