Skip to content

Commit

Permalink
Merge pull request #3 from plathanus-tech/2-issue/2-widget-not-proper…
Browse files Browse the repository at this point in the history
…ly-working-with-django-material-admin

Fix (widget): Corrects JS and Widget init method
  • Loading branch information
leandrodesouzadev authored Mar 2, 2022
2 parents 81da26e + 61e4c8d commit 942a17a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
24 changes: 15 additions & 9 deletions src/brazilian_zipcode/static/getAddressInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,28 @@ function createReadOnlyInput(label, value) {
const parentDiv = input.parentNode.parentNode.parentNode;

removeReadOnlyInput(label);
const div = document.createElement("div");
div.classList.add("form-row");
div.setAttribute("meta-id", label)
const externalDiv = document.createElement("div");
externalDiv.classList.add("form-row");
externalDiv.setAttribute("meta-id", label)


const innerDiv = document.createElement("div");
innerDiv.classList.add("input-field");

const valueDiv = document.createElement("div");
const labelElement = document.createElement("label");
const labelDiv = document.createElement("div");
labelDiv.classList.add("readonly-label");

const labelElement = document.createElement("label");
labelElement.innerText = label + ":";
labelElement.classList.add("required");
div.appendChild(labelElement);
innerDiv.appendChild(labelElement);

valueDiv.classList.add("readonly");
valueDiv.innerText = value;
div.appendChild(valueDiv);
innerDiv.appendChild(valueDiv);

parentDiv.appendChild(div);
externalDiv.appendChild(innerDiv)
parentDiv.appendChild(externalDiv);
}

function getAddressInfo(zipcode) {
Expand Down Expand Up @@ -83,6 +89,6 @@ function handleOnFocusOutEvent(event) {


$(document).ready(function () {
const input = document.querySelector(zipcodeMetaId);
const input = document.querySelector(zipcodeSelector);
input.addEventListener("focusout", handleOnFocusOutEvent)
});
4 changes: 2 additions & 2 deletions src/brazilian_zipcode/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@


class AutoBrazilianZipCodeInput(widgets.TextInput):
def render(self, name, value, **attrs):
def render(self, name, value, attrs, renderer):
attrs["meta_id"] = "meta_zipcode_info"
return super().render(name, value, attrs)
return super().render(name, value, attrs, renderer)

class Media:
js = ("getAddressInfo.js",)

0 comments on commit 942a17a

Please sign in to comment.