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

DBForeignKey has_one Dropdown fields resort to a NumericField for >100 objects #7788

Closed
brew-jay opened this issue Jan 23, 2018 · 2 comments · Fixed by #7789
Closed

DBForeignKey has_one Dropdown fields resort to a NumericField for >100 objects #7788

brew-jay opened this issue Jan 23, 2018 · 2 comments · Fixed by #7789

Comments

@brew-jay
Copy link

brew-jay commented Jan 23, 2018

Description

When using scaffolding to generate a has_one field using a model admin.

The has_one field generates a nice dropdownfield. However if the count of objects goes above 100 the field just resorts to numeric Field.

This becomes extremely frustrating from a UX Point of View where the CMS works and looks nice, but if the client adds more than 100 objects then it breaks the experience.

It should at least be configurable?
Offending code.

if ($list->count() < 100) {
            $field = new DropdownField($this->name, $title, $list->map('ID', $titleField));
            $field->setEmptyString(' ');
        } else {
            $field = new NumericField($this->name, $title);
        }

This isn't mentioned in the documentation either, so it's caught us out where we've put a site live and a customer has raised this as a bug and affected their day-day running as they can't select a has-one object.

Steps to Reproduce

Create a data object with a has_one to another dataobject. Allow scaffolding to create the fields using a model admin.

You'll see a nice dropdown box is used. If you then add over 100 dataobjects. That has_one field resorts to a Numeric Field.

@tractorcow
Copy link
Contributor

tractorcow commented Jan 23, 2018

In this case it's necessary for you to declare a getCMSFields for your custom model, and override this specific field. The default scaffolder isn't intended as a primary source of UX, just a default baseline you can use to get started.

public function getCMSFields()
{
	$fields = parent::getCMSFields();
	$fields->replace(
		'RelationID',
		new DropdownField('RelationID', 'Select Relation', MyObject::get()->map('ID', 'Title')
	);
	return $fields;
}

@maxime-rainville
Copy link
Contributor

I think this recent changes fixes this #11071

@maxime-rainville maxime-rainville closed this as not planned Won't fix, can't repro, duplicate, stale May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants