What causes the variance in behavior between the Angular-formly directive and type?

I am facing an issue with two input fields that are both generated using the same template. I have set the required attribute to true for both of them by using the following code snippet:

...    
templateOptions: {
  ...
  required: true
}

One input field is registered through the formlyConfig.setType method, while the other is registered using a directive. To demonstrate this issue, I have created a JS Bin here.

However, only the first input field is displaying the required attribute, while the second one is not. According to the documentation on custom templates (controller option), it states:

Provides you the ability to add custom behavior to the type without having to make an entire directive (you can make a directive instead if you wish).

Can anyone help me identify what mistake I might be making in this scenario?

Answer №1

When angular-formly processes the options with a template in the second example, it only sees <plain-text>. As a result, it is unable to determine which element should have the required attribute applied. This is because angular-formly will only add attributes like this to elements that have an ng-model, as these are the only elements where the attribute is appropriate.

The important thing to note is what angular-formly perceives when processing the template (before compilation), rather than what the directive compiles to. While using your own directive is possible, if you want to take advantage of angular-formly's features, it must incorporate the ng-model controller (similar to the directive used in this example).

Best of luck!

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 similar alternative to ignoring in webpack or browserify?

My code works perfectly in the browser after ignoring two packages with browserify: browserify files.js -i fs-extra -i request --standalone files > files.browserify.js. However, when I try to use webpack instead, the code throws errors about missing mod ...

Running multiple instances of setTimeout() in JQuery

I'm looking for a way to delay the execution of 10 lines of independent jQuery code with 2 seconds between each line. I initially tried using setTimeout() on each line, but is there a more elegant solution for this scenario? The jQuery DELAY method do ...

Tips for validating Angular form group input depending on the value of another input within the form?

I am facing an issue with form validation in my Angular version 8 application. I need to validate a form based on the following rules: If a file is uploaded (even if just clicking the button without selecting a file), then the Reason input is not required ...

Update input field value with data retrieved via ajax call in AngularJS

My current approach involves using AngularJS directives for Bootstrap in order to create an edit form on a Bootstrap modal when the user clicks on the edit button from a list of items. Here is the code I have implemented: HTML: <div class="modal-heade ...

Enhance JQuery functionality using Typescript

Currently, I am in the process of developing a Typescript plugin that generates a DOM for Header and attaches it to the page. This particular project utilizes JQuery for handling DOM operations. To customize the plugin further, I aim to transmit config Opt ...

Using Angular directives with Kendo UI Grid to create a foreign key column

I'm currently working on building a Kendo Grid that incorporates 2 foreign key columns using the Angular directives for Kendo. The challenge I am facing is that while one column works perfectly fine, the other does not (each works independently of the ...

Which is quicker when utilizing jQuery selectors: selecting by .classname or div.classname?

Which is quicker: using $(".classname"). or adding the tag to search for as well? $("div.classname") In my opinion, using just the classname would be faster because jQuery can simply loop through all classnames directly, whereas in the second example i ...

Navigating Tabs the AngularJS / Bootstrap Way: Best Practices

Looking to implement tab-based navigation for a website using AngularJS and Bootstrap in the most effective manner possible. So far, I've discovered that following the guidelines of the AngularJS Seed is considered the best approach for setting up an ...

Modifying the onclick function for a bootstrap glyphicon

How can I swap the .glyphicon-menu-down to glyphicon-menu-up when a user clicks on a link? Currently, it's not working as expected. Could there be an issue with my jQuery implementation? Markup <a data-toggle="collapse" data-parent="#accordion" h ...

PHP jQuery buttons for popovers

With a simple click of a button, I can generate 8 presentations and then edit each one individually by clicking on its respective name. Within this editing process, there is another form where I would like to include additional buttons that allow me to cus ...

Call getElementById upon the successful completion of an AJAX request

In the process of constructing a mini quiz, I am utilizing a variable quizScore to store the score. Each question in the quiz is displayed using AJAX. An individual AJAX call captures the ID of the button pressed (for example, on question 2, the button ID ...

Transmit an array in a post request with Node.js using the application/x-www-form-urlencoded content type

After attempting to send a post request to an API with post parameters as an array, I encountered difficulties. Here is how it can be done using cURL: curl http://localhost:3000/check_amounts -d amounts[]=15 \ -d amounts[]=30 I then tried to ach ...

Node.js equivalent of hash_hmac

I am facing an issue while trying to sign the URL in a Node.js application similar to how it is done in my PHP app. In PHP, I use the following code to sign the URL: private static function __getHash($string) { return hash_hmac('sha1', $stri ...

Tips on containing the reach of a function in JavaScript/jQuery

I have a scenario where I have multiple .js files linked on the page, each containing functions with the same name. For example: first.js function DisplayContent(data,$target) // data is string { $target.html('<span>'+ data +'&l ...

Adding text chips to a text field in Vuetify - A simple guide

I have successfully integrated a text field with vuetify and now I am looking to incorporate chips into it. Currently, chips are only added if the entered text matches a specific pattern (such as starting with '{' and ending with '}'). ...

Tips for implementing JWT in a Node.js-based proxy server:

I am a Node.js beginner with a newbie question. I'm not sure if this is the right place to ask, but I need ideas from this community. Here's what I'm trying to do: Server Configurations: Node.js - 4.0.0 Hapi.js - 10.0.0 Redis Scenario: ...

Encountering an issue with Angularjs 1.7.7 + webpack where only the production build is displaying an injector module error. Any suggestions on

I have embarked on the process of transitioning my angularjs (1.7.7) app to webpack. Here is my configuration in webpack.config.js - const webpack = require('webpack'); const path = require('path'); const HtmlWebpackPlugin = require(" ...

Adjust the settings of a CSS element

Apologies as I am still new to this and struggling to implement the correct code. I am attempting to modify the background color of a custom marker in leaflet.js. Essentially, I need to adjust the CSS element's value. I have the CSS code and how I am ...

How can you loop through keys and values in a JSON object using JavaScript?

I am attempting to cycle through the JSON data below: { "VERSION" : "2006-10-27.a", "JOBNAME" : "EXEC_", "JOBHOST" : "Test", "LSFQUEUE" : "45", "LSFLIMIT" : "2006-10-27", "NEWUSER" : "3", "NEWGROUP" : "2", "NEWMODUS" : "640" } The keys in this JSON are d ...

Ways to determine the final page of pagination on ui-grid in angular js

If you need to implement pagination in your application using AngularJS and ui-grid, this is the pagination API for you. gridApi.pagination.on.paginationChanged($scope, function(newPage, pageSize) { var grid = this.grid; paginationOptions.pageNumber ...