question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creating a custom widget

See original GitHub issue

Question received by email:

I have a question regarding the angular2-schema-form repo. You say that it is possible to generate your own widget, sadly I don’t understand how and where I should begin. Could you give me some information or documentation regarding creating your own widget?

You need to derivate the widget you want to customize:

@Component({
  selector: 'mdl-sf-string-widget',
  templateUrl: './string.widget.html'
})
export class MyStringWidget extends StringWidget {}

You need to provide its html template (let’s imagine we want to use the Material Design text field):

<mdl-textfield [label]="schema.description" type="string" floating-label 
    [name]="name" [attr.readonly]="schema.readOnly?true:null"
    [attr.id]="id"
    [attr.disabled]="schema.readOnly?true:null"
    [formControl]="control"></mdl-textfield>

And you need to declare it in a custom registry:

import { MyStringWidget } from './mystring';

export class MyWidgetRegistry extends DefaultWidgetRegistry {
  constructor() {
    super();

    this.register('string',  MyStringWidget);
  }
}

And then you need to provide your registry in your module:

providers: [{provide: WidgetRegistry, useClass: MyWidgetRegistry}],

Note: I will add this to the doc

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

1reaction
ebrehaultcommented, Apr 18, 2017

Sorry, StringWidget can be imported from the angular2-schema-form package (the code is here: https://github.com/makinacorpus/angular2-schema-form/blob/master/src/defaultwidgets/string/string.widget.ts )

0reactions
manuelartecommented, Aug 6, 2017

Hi @marc101101 , I can see changes in the ui. The widget registration is working perfectly (well… not the binding to the value haha).

I edit the post saying that I can also see the [formControl]=control value changed

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Create Custom Widgets on iPhone - How-To Geek
Now, go to the “My Widgets” tab and tap the “Add (Size) Widget” for the size of the widget you want to create....
Read more >
How to Customize Your iPhone With Widgets - HelloTech
To create your own widgets, download the Widgetsmith app. Then open the app, choose a widget size, and then customize it. Next, add...
Read more >
Create a custom widget - D2L
Create a custom widget · On the Course Home page, click Course Admin > Widgets > Create Widget. · Enter a name and...
Read more >
iOS 14 Homescreen Setup - Tips/Tricks + Favorite ... - YouTube
How to customize your iPhone on #iOS 14 using custom widgets plus sharing a few tips and tricks. This setup is a nice...
Read more >
How to Create WordPress Custom Widgets
Create a new class that extends WP_Widget. · Begin with __construct() to determine widget's parameters. · Use widget() to define the appearance of ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found