-
Notifications
You must be signed in to change notification settings - Fork 34
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
Input field disappearing when clicking 'Add'. #386
Comments
@AmazingAkai This can be fixed by including optional parameter on this line piccolo_admin/admin_ui/src/components/ArrayWidget.vue Lines 118 to 120 in 1157c12
like this isMediaColumn() {
return this.schema?.extra.media_columns.includes(this.fieldName)
} Result is: add_button.webmBut then we have another problem because Piccolo Admin doesn't understand |
@sinisaos I think adding this for now makes sense: isMediaColumn() {
return this.schema?.extra.media_columns.includes(this.fieldName)
} At some point we need to refactor things a bit so |
@dantownsend I agree with you and it will solve a smaller part of the problem. The larger part is that Piccolo Admin can't understand the |
Yeah, OpenAPI schemas are surprisingly complex - especially the references etc. |
@AmazingAkai I was thinking about how we could use a Python enum in array widget select in custom forms. I tried to mimic the Piccolo array column select and came up with this. These are the changes that should be made. We need to add this line of code to the NewForm.vue <InputField
v-bind:isFilter="false"
v-bind:key="columnName"
v-bind:columnName="String(columnName)"
v-bind:type="getType(property)"
v-bind:value="property.default"
v-bind:choices="property.extra?.choices" // new line
v-bind:timeResolution="
schema?.extra?.time_resolution[columnName]
"
/> After that, build the Vue frontend and add the # Permission enum is same as before
# with this we mimic Piccolo array column choices
choices = {}
for item in Permission:
choices[item.name] = {
"display_name": item.name,
"value": item.value,
}
class NewStaff(BaseModel):
name: t.Annotated[str, Field(max_length=255, pattern=r"^[a-zA-Z\s]+$")]
email: EmailStr
superuser: bool
permissions: t.List[t.Any] = Field(extra={"choices": choices}) # usage of choices Result is this enum_select.webmThis isn't perfect, but it might work in your case. I hope you find this useful. |
Oh interesting, its better than nothing, thanks! |
@dantownsend would it be good to add class Permission(str, enum.Enum):
UPLOADS = "uploads"
NOTICES = "notices"
GALLERY = "gallery"
ADMISSIONS = "admissions"
def custom_form_choices() -> t.Dict[str, t.Any]:
choices = {}
for item in Permission:
choices[item.name] = {
"display_name": item.name,
"value": item.value,
}
return choices
class NewStaff(BaseModel):
name: t.Annotated[str, Field(max_length=255, pattern=r"^[a-zA-Z\s]+$")]
email: EmailStr
superuser: bool
permissions: t.Any = Field( # or permissions: t.List[t.Any] if we want a list of selects as in the previous comment video
json_schema_extra={"extra": {"choices": custom_form_choices()}}
) Result is this custom_form_select.webmWhat do you think about it? |
@sinisaos I'm still having the same issue, I'm using |
I wonder if installing it from GitHub doesn't work because the Vue code isn't compiled into static assets. I'll do a proper release later today. |
Try |
That exactly the case. If we want to use Piccolo Admin from Github, we need to compile the static files ourselves. With the new release, everything works as expected. |
@sinisaos It's an interesting idea. I never considered this before: permissions: t.Any = Field( # or permissions: t.List[t.Any] if we want a list of selects as in the previous comment video
json_schema_extra={"extra": {"choices": custom_form_choices()}}
) Is this just a documentation change, or requires other code changes? |
@dantownsend Basically the only code change is adding a |
Permission is just an enum
Screencast_20240425_213515.webm
The text was updated successfully, but these errors were encountered: