-
Notifications
You must be signed in to change notification settings - Fork 63
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
Actions with fields instead of plain html #375
Conversation
for more information, see https://pre-commit.ci
…san/starlette-admin into actions-with-fields
I figured it out why I believe we need to wait for #444 to be resolved before merging this, and we should turn the Note: You might ask "What do you mean by self-calling function", I don't know what JS people call this: (function () {
function processElement(element) {
// Logic
}
$(function () {
processElement(document);
});
})();
|
I have found two solutions for this:
@row_action(
name="action",
text="My Action",
confirmation="Are you sure?",
form="""
<form>
</form>
<script type="text/javascript" src="/admin/statics/js/form.js"></script>
""",
)
/**
* Initialize actions that trigger a modal dialog for user confirmation.
*/
initActionModal() {
let self = this;
$("#modal-action").on("show.bs.modal", function (event) {
let button = $(event.relatedTarget); // Button that triggered the modal
let confirmation = button.data("confirmation");
let form = button.data("form");
let name = button.data("name");
let submit_btn_text = button.data("submit-btn-text");
let submit_btn_class = button.data("submit-btn-class");
let customResponse = button.data("custom-response") === true;
let isRowAction = button.data("is-row-action") === true;
let modal = $(this);
modal.find("#actionConfirmation").text(confirmation);
let modalForm = modal.find("#modal-form");
modalForm.html(form);
let actionSubmit = modal.find("#actionSubmit");
actionSubmit.text(submit_btn_text);
actionSubmit.removeClass().addClass(`btn ${submit_btn_class}`);
actionSubmit.unbind();
actionSubmit.on("click", function (event) {
const formElements = modalForm.find("form");
const form = formElements.length ? formElements.get(0) : null;
self.submitAction(name, form, customResponse, isRowAction, button);
});
let scriptEle = document.createElement("script");
scriptEle.setAttribute("src", "/admin/statics/js/form.js");
document.body.appendChild(scriptEle);
scriptEle.addEventListener("load", () => {
console.log("File loaded")
});
scriptEle.addEventListener("error", (ev) => {
console.log("Error on loading file", ev);
});
});
}
I don't think either way is the best, I believe |
for more information, see https://pre-commit.ci
…san/starlette-admin into actions-with-fields
Due to #505, I'm closing this one. |
There are certain times when my actions have a bunch of inputs... Writing plain HTML for those inputs doesn't seem right since we have a
field
system which is awesome and somewhat similar to WTForms.It doesn't work properly on some fields like
RelationField
andBooleanField
. I will work on those when/if this PR gets merged.What are your thoughts?