Skip to content

AmountField does not work as documented #1341

@jrief

Description

@jrief

It took me quite a while to figure out that the documentation on Adding Custom Types, using the AmountField sample code, seems not to work as described.

What I did: I have set up a project using the same dependencies as provided by the ng-admin-demo. Compiling and running the demo using webpack works well. There is no difference to the online version of it.

Then I started to create a simple project from scratch, using the sample code from Adding Custom Types. Afterwards I added a field of type amount using

	var admin = nga.application("Dashboard");
	admin.baseApiUrl("/my/rest/endpoint/");

	var entity = nga.entity("extra");
	entity.label("Extra");

	entity.listView().fields([
		nga.field("id", "string"),
		nga.field("product_name", "string"),
	]);

	entity.creationView().fields([
		nga.field("id", "string"),
		nga.field("product_name", "string"),
		nga.field("price", "amount")
	]);

	entity.editionView().fields([
		nga.field("id", "string"),
		nga.field("product_name", "string"),
		nga.field("price", "amount")
	]);

	admin.addEntity(entity);

this dashboard display the fields id and product_name but hides the expected field price. When I change the field type to float or number, everything works as expected, but of course that's not the purpose of this exercise.

Then I debugged into the compiled ES5 code and I can confirm that the constructor of the AmoutField is invoked. However, if the field type is set to amount the field is not rendered, only the most outer, but empty wrapper:

<div ng-repeat="field in ::formController.fields track by $index" compile="::field.getTemplateValueWithLabel(entry)" class="ng-scope"></div>

May it be that a customized field also must override the getTemplateValueWithLabel method in order to fill its content?

Since the amount field is working in the demo, I was searching for an error in my setup. However, in the demo, the templates used to render the Catalog > Poster > Detail View are overridden anyway, so there the amount field is not used as described in the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions