Reusing Markup with a Generic Text Field Component

You’ve already seen how to reuse markup when we created the AddressComponent in Chapter 11, Asynchronously Load Data from Many Sources. Our TextFieldComponent is even more generic, so we will need to have a few more properties that the user has to set. To make this generic, we need to get a few bits of information from the user:

  • The name of the field being edited

  • A label to use for the field

  • An optional flag for the addon (you’ll recall from Form Add-Ons that we added nicely styled @ in front of the username control)

Let’s see how those values would be used in our markup. A completely generic version of our text field would now look like this:

Get Rails, Angular, Postgres, and Bootstrap, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.