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.

Custom buttons with HtmlType="submit" logic in ModalFooter

See original GitHub issue

I have been trying for couple of days to get this working without success. Also checked Google and can’t find any solution. I am trying to make a modal window that would have scroller inside content and there would be Header and Footer. I would like to perform validation as well before closing Modal window.

Here is working solution, but buttons are not in Footer and are scrolled with content, that makes them hard to find as they are not attached to the bottom of dialog all the time.

<Modal Title="Create new record"
       Style="width:80%"
       BodyStyle="height:65vh;overflow-y:auto;"
       Visible="@this.isDialogVisible"
       Draggable="@(true)"
       Footer="null"
       OnCancel="(e)=>{this.isDialogVisible = false;}">
  <Form Model="this.RecordModel"
        Layout="@FormLayout.Vertical"
        OnFinish="(e) => this.OnCreateNewDiaryRecord()">
    <div>
      <NewRecord Record=this.RecordModel />
    </div>
    <br />
      <FormItem WrapperColOffset="8" WrapperColSpan="16">
        <Button Type="@ButtonType.Primary" HtmlType="submit">
          Submit
        </Button>
        <Button OnClick="(e)=>{this.isDialogVisible = false;}">Cancel</Button>
      </FormItem>
  </Form>
</Modal>

I have tried this:

@{
  RenderFragment footer = @<Template>
    <Button Type="@ButtonType.Primary" @key="@( "submit" )" HtmlType="submit" Loading="@_loading">
      Submit
    </Button>
    <Button OnClick="(e)=>{this.isDialogVisible = false;}">Cancel</Button>
  </Template>;
}

<Modal Title="Create new record"
       Style="width:80%"
       BodyStyle="height:65vh;overflow-y:auto;"
       Visible="@this.isDialogVisible"
       Draggable="@(true)"
       Footer="@footer"
       OnCancel="(e)=>{this.isDialogVisible = false;}">
  <Form Model="this.RecordModel"
        Layout="@FormLayout.Vertical"
        OnFinish="(e) => this.OnCreateNewRecord()">
    <div>
      <NewRecord Record=this.RecordModel />
    </div>
    <br />
  </Form>
</Modal>

But Submit button does not function in this case correctly = does nothing. However in layout perspective everything looks as expected. So then I have tried this:

<Modal Title="Create new record"
       Style="width:80%"
       BodyStyle="height:65vh;overflow-y:auto;"
       Visible="@this.isDialogVisible"
       Draggable="@(true)"
       OnCancel="(e)=>{this.isDialogVisible = false;}">
  <Form Model="this.RecordModel"
        Layout="@FormLayout.Vertical"
        OnFinish="(e) => this.OnCreateNewDiaryRecord()">
    <div>
      <NewRecord Record=this.RecordModel />
    </div>
    <br />
  </Form>
  <ModalFooter>
    <div>
      <Button Type="@ButtonType.Primary" HtmlType="submit">
        Submit
      </Button>
      <Button OnClick="(e)=>{this.isDialogVisible = false;}">Cancel</Button>
    </div>
  </ModalFooter>
</Modal>

But I am getting exception about ChildContent = no Footer visible. Is there any way to get Custom buttons with Submit logic into Footer?

This is what I am trying to achieve:

  1. Default dialog = modal window with Header, Content and Footer sections
  2. Dialog has fixed Height property (either px or %) and scroller appears automatically in content section if after unhiding items in Panel’s Height of dialog exceeds set value.
  3. OK button changed to OkText="@("Submit")" and has HtmlType="submit" logic

I ended up with this code, but it does not “validate” on Submit button pressed (does not highlight error inputs in Dialog like default HtmlType="submit" does):

<Modal Title="Create new record"
       Style="width:80%"
       BodyStyle="height:65vh;overflow-y:auto;"
       Visible="@this.isDialogVisible"
       Draggable="@(true)"
       OkText="@("Submit")"
       ConfirmLoading="@this.confirmationButtonIsLoading"
       OnOk="this.OnSubmitRecord"
       OnCancel="(e)=>{this.isDialogVisible = false;}">
  <Form Model="this.RecordModel"
        ValidateMode="@FormValidateMode.Rules"
        ValidateOnChange="@validateOnChange"
        Layout="@FormLayout.Vertical"
        OnFinish="(e) => this.OnSubmitRecord()"
        OnFinishFailed="(e)=>{this.isDialogVisible = true;}">
    <div>
      <NewRecord Record=this.RecordModel />
    </div>
    <br />
  </Form>
</Modal>

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
vadimffecommented, Jan 24, 2022

@zxyao145 for me it seems to work now as expected. I can probably close this issue. Thank you for example!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Left & right align modal footer buttons in Bootstrap 4
Bootstrap 4 uses flex-box for it's modal footers. If I want two buttons, one on the left and one on the right, how...
Read more >
bootstrap 3 modal footer align buttons on both edges
How can I align buttons in modal's footer so they are on both sides of modal ? Default behaviour sets all buttons near...
Read more >
Modal · Bootstrap
Use Bootstrap's JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
Read more >
Modal | Components
These buttons can be customized by setting various props on the component. You can customize the size of the buttons, disable buttons, hide...
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