Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change the height of a multiline text input? #52

Closed
alvaromb opened this issue Sep 8, 2015 · 11 comments
Closed

How to change the height of a multiline text input? #52

alvaromb opened this issue Sep 8, 2015 · 11 comments

Comments

@alvaromb
Copy link
Collaborator

alvaromb commented Sep 8, 2015

I'm struggling to change the height of a multiline input inside a form. Do I have to define an entire stylesheet for that element just for changing one property?

@gcanti
Copy link
Owner

gcanti commented Sep 8, 2015

Do I have to define an entire stylesheet for that element just for changing one property?

No, you can override the stylesheet locally:

https://github.com/gcanti/tcomb-form-native#stylesheets

and in t.form.Form.stylesheet.textbox you find the default stylesheet for textboxes, split by

  • normal
  • error
  • notEditable

(see the file https://github.com/gcanti/tcomb-form-native/blob/master/lib/stylesheets/bootstrap.js#L62 for the complete code)

Example:

var Foo = t.struct({
  description: t.Str
});

var options = {
  fields: {
    description: {
      multiline: true,
      stylesheet: Object.assign({}, t.form.Form.stylesheet.textbox, {
        ...my overrides here...
      })
    }
  }
};

@alvaromb
Copy link
Collaborator Author

alvaromb commented Sep 9, 2015

I was doing exactly that but using underscore's extend and with that I was also modifying the default stylesheet. This is how I finally managed to do it (using es6 property spread):

options: {
  fields: {
   description: {
      multiline: true,
        stylesheet: {
          ...Form.stylesheet,
          textbox: {
            ...Form.stylesheet.textbox,
            normal: {
              ...Form.stylesheet.textbox.normal,
              height: 100
            },
            error: {
              ...Form.stylesheet.textbox.error,
              height: 100
          }
        }
      }
    },
  }
}

@alvaromb alvaromb closed this as completed Sep 9, 2015
@mintotsai
Copy link

For future reference, here is how I solved this:

var immutableMap = Immutable.fromJS(t.form.Form.stylesheet);
var immutableMerge = immutableMap.mergeDeep({textbox: {normal: {height: 100}}})
var tcombStyle = immutableMerge.toJS();
options.fields[item.name] = {
                                        label: [item.label],
                                        multiline: true,
                                        numberOfLines: 5,
                                        stylesheet: tcombStyle
                                      };

@weixingsun
Copy link

Hi, looks like all above are fixed height,

I am trying to implement an auto-grow TextInput like the official docs:
https://facebook.github.io/react-native/docs/textinput.html
But I found the onChange event was used to track for text only,
Is there an existing way to access the nativeEvent object from tcomb-form like this: "event.nativeEvent.contentSize.height" ?
Please let me know if you have any suggestions, thanks! I had tried several times but failed,

@gcanti
Copy link
Owner

gcanti commented May 27, 2016

But I found the onChange event was used to track for text only

@weixingsun looks like we use onChangeText(text):

https://github.com/gcanti/tcomb-form-native/blob/master/lib/templates/bootstrap/textbox.js#L64

Is there an existing way to access the nativeEvent object from tcomb-form

we could add an onChange(event) handler to TextInput

@weixingsun
Copy link

Thanks for your quick answer, it will be really helpful.
Also, I am thinking that, the initial idea is to make the textbox auto-growable,
I think it will be much easier for a developer if there is a way to create a prop, like "auto-grow=true"
what do you think?

@gcanti
Copy link
Owner

gcanti commented May 27, 2016

@weixingsun in general for this kind of things I'd prefer to provide low level APIs and let people implement its own customised solutions

@weixingsun
Copy link

Ok, that is good enough, thanks for your help!

@gcanti
Copy link
Owner

gcanti commented May 27, 2016

@weixingsun you can track the new feature here #168

@weixingsun
Copy link

@gcanti thanks for your help, do you know if there is any method to show multiline textbox for default value? My detail content field show only one line, any idea?

@atgitdeepak
Copy link

I was doing exactly that but using underscore's extend and with that I was also modifying the default stylesheet. This is how I finally managed to do it (using es6 property spread):

options: {
  fields: {
   description: {
      multiline: true,
        stylesheet: {
          ...Form.stylesheet,
          textbox: {
            ...Form.stylesheet.textbox,
            normal: {
              ...Form.stylesheet.textbox.normal,
              height: 100
            },
            error: {
              ...Form.stylesheet.textbox.error,
              height: 100
          }
        }
      }
    },
  }
}

The solution worked in terms of designing but when I top on the field to write something, It takes the cursor to the middle of the box, unable to start writing from top left corner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants