Giter VIP home page Giter VIP logo

Comments (7)

adamcooke avatar adamcooke commented on May 22, 2024

Do you mean the initially selected option? If so, you'll want something like this:

row.selectorOptions = @[
    [XLFormOptionsObject formOptionsObjectWithValue:@(1) displayText:@"Option 1"],
    [XLFormOptionsObject formOptionsObjectWithValue:@(2) displayText:@"Option 2"],
    [XLFormOptionsObject formOptionsObjectWithValue:@(3) displayText:@"Option 3"],
];
row.value = [XLFormOptionsObject formOptionsObjectWithValue:@(2) displayText:@"Option 2"];

from xlform.

zenomoung avatar zenomoung commented on May 22, 2024

Thanks for your reply.
Indeed I meant the initially selected option.
I save in my backend the selected XLFormOptions value (in this case '2'). I thought I just had to set row.value = 2 to have the XLFormOptionsObject displayed and selected.
Is this the case? Do I have to set the whole XLFormOptionsObject ([XLFormOptionsObject formOptionsObjectWithValue:@(2) displayText:@"Option 2"])?
Thanks

from xlform.

adamcooke avatar adamcooke commented on May 22, 2024

That's correct.

from xlform.

zenomoung avatar zenomoung commented on May 22, 2024

I guess you mean to set the whole whole XLFormOptionsObject.
It would be nice to have it as a dictionary: I give the key, it displays the text.
Thanks for this control.

from xlform.

adamcooke avatar adamcooke commented on May 22, 2024

You can avoid creating a new XLFormOptionsObject instance by selecting a value from the row.selectorOptions array. Like so:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"formValue == %@", @(3)];
row.value = [[row.selectorOptions filteredArrayUsingPredicate:predicate] objectAtIndex:0];

You can replace 3 with the form value of the object you want selected.

from xlform.

mtnbarreto avatar mtnbarreto commented on May 22, 2024

@batouri ,

You can get the reference to any XLFormOptionsObject using the convenient method +(XLFormOptionsObject *)formOptionsOptionForValue:(id)value fromOptions:(NSArray *)options;. Basically it does exactly the same @adamcooke suggests above.

Take a look at XLFormOptionsObject class definition...

@interface XLFormOptionsObject : NSObject <XLFormOptionObject>

+(XLFormOptionsObject *)formOptionsObjectWithValue:(id)value displayText:(NSString *)displayText;
+(XLFormOptionsObject *)formOptionsOptionForValue:(id)value fromOptions:(NSArray *)options;
+(XLFormOptionsObject *)formOptionsOptionForDisplayText:(NSString *)displayText fromOptions:(NSArray *)options;

@end

You can also take a look at https://github.com/xmartlabs/XLForm#selector-rows to see how to use another class as selector option. You can use some basic types, for example NSString, or any class that conforms to XLFormOptionObject protocol (XLFormOptionsObject conforms to it and it's just a convenience class).

from xlform.

zenomoung avatar zenomoung commented on May 22, 2024

Great! Thanks

from xlform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.