ng-admin fails to identify custom field view

I've been exploring ng-admin.
After referring to the documentation, I decided to create a custom field.
However, even though ng-admin recognizes the FooFieldType, it is not rendering the FoofieldView and instead using the original FieldView!

Configuration Module:

angular.module('admin', ['ng-admin']);

import FooField from './FooFieldType';

angular.module('admin')
  .config(['NgAdminConfigurationProvider', function (nga) {
    nga.registerFieldType('foo', FooField);
  }])
  .config(['FieldViewConfigurationProvider', function (fvp) {
    fvp.registerFieldView('foo', require('./FooFieldView'));
  }])
  ;
angular.module('admin').config(['NgAdminConfigurationProvider', function (nga) {
   var bar = nga.entity('bar');
   bar.creationView().fields([nga.field('foo','foo')]);
});

FooField.js:

import Field from 'admin-config/lib/Field/Field';
class FooField extends Field {
  constructor(name) {
    super(name);
  }
}
export default FooField;

FooFieldView.js:

export default {
  // displayed in listView and showView
  getReadWidget   : () => '<ma-number-column field="::field" value="::entry.values[field.name()]"></ma-number-column>',
  // displayed in listView and showView when isDetailLink is true
  getLinkWidget   : () => '<a ng-click="gotoDetail()">' + module.exports.getReadWidget() + '</a>',
  // displayed in the filter form in the listView
  getFilterWidget : () => '<ma-input-field type="number" field="::field" value="values[field.name()]"></ma-input-field>',
  // displayed in editionView and creationView
  getWriteWidget  : () => '<h1>testFoo</h1><ma-input-field type="number" field="::field" value="entry.values[field.name()]"></ma-input-field>'
};

Answer №1

It appears that there is a crucial detail missing from the documentation regarding the 'this._type' setting in the Field class. To resolve this, you must make changes to FooField.js by adding the following line:

....
class FooField extends Field {
  constructor(name) {
    super(name);
    //THIS IS THE IMPORTANT PART:
    this._type = 'foo';
    //DOC DOESN'T SPEAK ABOUT
  }
}
....

By defining _type in the FooField class, the appropriate view based on type will be rendered. Without this setting, only the default String view will be displayed, resulting in functionality issues.

The documentation definitely needs an update :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to run a node script from any location in the command line similar to how Angular's "

Currently, I am developing a node module that performs certain functions. I want to create a command similar to Angular's ng command. However, I am facing compatibility issues with Windows and Linux operating systems. Despite my attempts to modify the ...

Pulling information from a database query to store it within a JavaScript variable

Using Ajax/JQuery, I successfully send the variable ($name) from page1.php to page2.php without refreshing the page. When the submit button is clicked, it sends me the var $name effectively. Additionally, in my JavaScript library for charts (AmCharts), the ...

What is the best way to extract values from promises that are still pending?

Having some issues with the code below and unable to achieve the desired output. Any help in identifying what's wrong would be greatly appreciated. Thanks! Here is the code: // Making http requests const getJSON = require('get-json'); ...

Having trouble with my TinyMCE Editor not loading content data in the Edit.vue component of my Vue 3 project with Vite

I am currently working on a Vue 3 project using Vite and incorporating Editor.vue components with TinyMCE. The code snippet for my Editor.vue component is shown below: My Editor.vue code: <template> <div class="mb-6"> < ...

Preloading videos for optimal performance on mobile devices

Looking for a solution where 4 MP4/video files, each 5MB in size, can be played consecutively without gaps between them on all browsers and devices. Preferably not looking for a solution involving the replacement of video source files. The current approac ...

Stopping an HTML5 range input at a specific number: Tips and tricks

Does anyone have suggestions on how to use angularjs to stop a range slider at 75? I attempted it but it doesn't seem like the best approach. Any guidance would be appreciated. [EDIT for clarification after max=75 answer] Just to clarify, I want to di ...

The page is constantly updating on its own

In my React app, the App component checks for a token in local storage upon loading. If a token is found, it is verified. If the token is valid, the user is directed to the dashboard; otherwise, they are taken to the login page. The issue I am facing is ...

Troubleshooting Vue.js and Laravel: Having trouble loading new image files, while the older ones load just fine

Currently, I am working on a project that involves Vue.js and Laravel. In this setup, Vue is located inside the resources/js directory of the Laravel project. My current issue revolves around loading an image from the resources/js/assets directory. While ...

Seeking help with a Javascript regex inquiry

I am currently utilizing JavaScript regex for the following task: I have gathered the HTML content from a page and stored it within a string. Now, I aim to identify all URLs present on this page. For instance, if the document includes-- <script src = ...

Positioning elements at the bottom of the container

There is a dilemma that only those in the world of web development will understand. Beware! I have envisioned a layout for a website I am constructing. The concept involves tilted <hr/> elements on the page, with text wrapping around them (refer to ...

Extract specific data points from external API responses on a webpage crafted in HTML

I require assistance on how to extract individual values from an HTML page. I received a response from the PAYU payment gateway team in HTML format, but I need to retrieve specific attribute values related to the transaction details. Below is the response ...

The correct method for creating an external JSON file

As I browse through numerous JSON tutorials online, including those on STO, I find myself in a state of confusion when it comes to determining the right approach for writing an external JSON file. I have come across various examples such as: (although Ad ...

Chosen Dropdown selection - Retrieve/Receive information

One of the challenges I'm facing involves a dropdown list on my web form that contains various dates. My main query is: How can I retrieve data for the selected date from a MySQL database and present it to the user? Additionally, if the chosen date do ...

In search of assistance with a persistent react.js error plaguing my work

I keep encountering an error whenever I run npm start on a new project. Does anyone have any insight on how to resolve this issue? The problem might lie within the project dependency tree rather than being a bug in Create React App. Here is what you can ...

DxDataGrid: Implementing a comprehensive validation system for multiple edit fields

I'm currently working with a DxDataGrid within an Angular Application. Within this particular application, I have the need to input four dates. I've implemented validation rules that work well for each individual field. However, my challenge aris ...

Assistance in using jQuery to locate specific div elements is

I am currently working on creating a navigation bar that features icons triggering contextual submenus upon hover. The main idea is that hovering over an icon will display a popup menu or tooltip with additional options, while still allowing the icon itsel ...

Horizontal navigation bar encroaching on slideshow graphics

I'm encountering difficulties aligning the horizontal menu below the image slider. When I have just an image without the slider, the menu aligns properly (vertically), but as soon as I introduce the code for the slider, the menu moves to the top and d ...

Triggering of NVD3 Angular Directive callback occurring prematurely

Lately, I've delved into utilizing NVD3's impressive angular directives for crafting D3 charts. They certainly have a sleek design. However, I'm encountering numerous challenges with callbacks. While callbacks function smoothly when incorpor ...

What is the best way to pass compile-time only global variables to my code?

I am looking for a way to easily check if my code is running in development mode, and based on that information, do things like passing the Redux DevTools Enhancer to the Redux store. I know I can use process.env.NODE_ENV for this purpose, but I find it ...

Outer div encapsulating inner div within its boundaries

I am looking for a solution where the inner div stays fully contained within the outer div, without overflowing and overlapping with the padding of the outer div. Here is a code sample that demonstrates the issue .inner { /* Overflow */ overflow-wra ...