Skip to content
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

<SelectField>: defaultValue does not work as expected #474

Open
Vrtak-CZ opened this issue Mar 20, 2023 · 3 comments
Open

<SelectField>: defaultValue does not work as expected #474

Vrtak-CZ opened this issue Mar 20, 2023 · 3 comments

Comments

@Vrtak-CZ
Copy link

Vrtak-CZ commented Mar 20, 2023

Hi,
Let me simplify my problem.

I have this schema.

export class Category {
    name = def.stringColumn().notNull()
    articles = def.oneHasMany(Article, 'articles')
}

export class Article {
    name = def.stringColumn().notNull()
    category = def.manyHasOne(Category, 'articles')
}

Then I have this simple form

const ArticleForm = Component(
	() => (
		<>
			<TextField field="name" label="Name" />
			<SelectField field="category" label="Category" options="Category.name" defaultValue="62522664-1681-49a8-85c9-21998ef4158c" />
		</>
	),
)
export default () => (
	<CreatePage
		entity="Article"
	>
		<ArticleForm />
	</CreatePage>
)

This will not throw any error and also not "preselect" Category with id 62522664-1681-49a8-85c9-21998ef4158c.

@matej21
Copy link
Member

matej21 commented Mar 20, 2023

Hi, you are problably using the custom component I've send you, right?
you are right that missing entity handling is not present, you can add an else branch and display an error message or whatever

		if (entity) {
			currentEntity.connectEntityAtField(field, entity)
		} else {
			// do stuff
		}

@Vrtak-CZ
Copy link
Author

Hi, you are problably using the custom component I've send you, right?

As workaround yes. But heavily modified.

Thats not point of this issue. I'm reporting weird behavior of implementation for native SelectField. Where I expect it to work or throw an error.

@matej21 matej21 added bug Something isn't working and removed bug Something isn't working labels Mar 20, 2023
@matej21
Copy link
Member

matej21 commented Mar 20, 2023

Thanks for clarifying that.

You are right that defaultValue for dynamic selects is currently silently omitted. It is in our internal backlog and defaultValue will be supported someday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants