marmelab / marmelab/ng-admin

AmountField does not work as documented

Open
#1,341 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
3.9k
Forks
703
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/marmelab/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](https://ng-admin-book.marmelab.com/doc/Custom-types.html). 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:

```


```

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the “Adding Custom Types” documentation and the AmountField constructor, then compare the scratch-project setup with the ng-admin-demo configuration and its overridden detail templates. Trace the getTemplateValueWithLabel entry point for an amount field; done means the documented sample renders the price field in creation and edition views.

Written by the indexing model from the issue text.

Assessment

Tech stack
angularjs, javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.