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.

Group fields together without changing the model structure?

See original GitHub issue

I know that you can use a template and basically display the fields however you like (as described here: https://github.com/gcanti/tcomb-form-native/issues/106) (I am doing that currently)

However I was wondering - I need some fields to be grouped together like you would do in html with a fieldset?

This is my model:

var model = t.struct({
	id: t.maybe(t.String),
	name: t.String,
	email: Email,
	street: t.maybe(t.String),
	zip: t.maybe(t.String),
	city: t.maybe(t.String),
	country: t.maybe(t.String),
	tel: t.maybe(t.String),

	manager: t.struct({
		name: t.maybe(t.String),
		lastname: t.maybe(t.String),
		tel: t.maybe(t.String),
		email: t.maybe(Email)
	}),
	notes: t.maybe(t.String),
	position: t.struct({
		latitude: t.Number,
		longitude: t.Number
	}),
});

name and email should be displayed together, steet, zip, city, country, tel as well.

Basic info:

  • name
  • email Address info:
  • street

Am I able to achieve this somehow just with the options? For the manager fields for example I can have a label for all the fields since it is a new struct. The issue with doing the same for name and email is that I would have to change the object structure. And then the value that comes from tform will be different…

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
compojoomcommented, Dec 7, 2016
function template(locals) {
    // in locals.inputs you find all the rendered fields
    return (
        <View>
            {locals.inputs.company_id}
            {locals.inputs.name}
            {locals.inputs.email}
            {locals.inputs.street}
            {locals.inputs.zip}
            {locals.inputs.city}
            {locals.inputs.country}
            {locals.inputs.tel}

            {locals.inputs.position}

            <View style={{marginTop: 10}}>
                <Text style={[{marginLeft: 20}, constants.styles.strong]}>Betriebsleiter</Text>
                {locals.inputs.manager}
            </View>

            <View style={{marginTop: 10}}>
                {locals.inputs.notes}
            </View>


        </View>
    );
}

and then just pass it to the options

0reactions
WebsByToddcommented, Dec 21, 2016

There might be a way to get the result you want this without a template. Here is a simple example of two side by side fields and a full width field without using templates.

const Person = t.struct({
	name: t.struct({
		firstName: t.String,
		lastName: t.String
	}),
	phone: t.Number
});

const parentStyle = _.cloneDeep(t.form.Form.stylesheet);
const childStyle = _.cloneDeep(t.form.Form.stylesheet);

parentStyle.fieldset.flex = 1;
parentStyle.fieldset.flexDirection = 'row';

childStyle.formGroup.normal.flex = 1;

const options = {
	fields: {
		name: {
			stylesheet: parentStyle,
			label: ' ',
			fields: {
				firstName: {
					stylesheet: childStyle
				},
				lastName: {
					stylesheet: childStyle
				}
			}
		}
	}
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Grouping Controls | Web Accessibility Initiative (WAI) - W3C
Grouping related form controls makes forms more understandable for all users, as related controls are easier to identify. It also makes it easier...
Read more >
How to group fields when serialising object with Marshmallow?
How to group fields together when serialising a flat-structured SQLAlchemy object with Marshmallow without changing the flat data structure ...
Read more >
Fields and Field Groups subpattern - Finance & Operations
Field and Field Groups is the most common data entry subpattern and uses a dynamic number of columns to present multiple fields or...
Read more >
Field Groups - Sanity.io
Using field groups in a document or object does not change the structure of the document, it only affects how and where fields...
Read more >
Solved: How to group fields - Microsoft Power BI Community
How to group fields ... I am not sure how simple it would seem but you can just add a slicer ... Then...
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