I need to know how to get the views from another layout xml file - kotlin-android-extensions

Is it possible to get the views from another layout using viewBinding?
or is there another way to get them?

Try this:
val binding = DataBindingUtil.inflate<FragmentFirstBinding>(LayoutInflater.from(requireContext()), R.layout.fragment_first, null, false)

Related

CarouselView.FormsPlugin get index of specific page

I'm using Carousel View by alexrainman for creating custom wizard.
I need to get index of specific page by its type (I don't know exactly which index would that page have).
Something like this:
var indexAdvanced = MyCarouselView.GetIndex<ContentView>(typeof(AdditionalDefectParametersContentView));
but of course, this code doesn't work. While creating this question, I've got an idea with using CarouselView's ItemsSource. How to do it properly? TIA.
By the way, I've already found an answer. >_<
The resulting code is:
// My CarouselView consists of ContentViews
_indexAdvanced = MyCarouselView.ItemsSource.Cast<ContentView>().
IndexOf(view => view is AdditionalDefectParametersContentView);
So it works!
Don't know what should I do: delete this question or leave? Maybe It would be useful for somebody, so I'll leave it for now.

What ComponentQuery should I use for this example in this.control()?

I have:
1.) What should I type in this.control() for getting the reference to the grid panel?
My plan is, when user double clicks one row, new tab is created. I already have code for creating new tabs but I just need to get reference to the grid panel.
Something like this:
'viewport > westpanel > accordion > gridpanel': {
doubleclick: function...
}
2.) Let's say that I gave an ID to the grid panel. How can I get reference in this.control using .get method?
3.) How can I be sure that I've got the right reference? Can I console.log() - it or something like that?
I would know how to do this without MVC but here I need help. :)
Thank you! :)
It is quite easy once you understand how to use it. First you should read the API about the ComponentQuery cause that is what is used within the control.
this depends on your components. You so can go by the xtype 'panel > grid': {itemdblclick:this.yourCallback}
the recommend way if you can't define a really unique path by xtypes '#myID': {itemdblclick:this.yourCallback} using defined refs within the control is not possible in the currently release, as far as I know.
Use Id's instead of just xtypes '#myID > grid': {itemdblclick:this.yourCallback} or define additional params '#myID > grid[customProp=identString]': {itemdblclick:this.yourCallback}

Change layout in controller depending on url

I have controller PlayerController and actions inside: View, Info, List.
So on urls "/Player/View" i get result with default Layout.
I want to get result with different Layout on request "/External/View".
How can i achieve this?
Although you can override the layout from the controller as has been suggested in another answer, in my opinion this means the controllers are getting just too involved in determining what the UI will be. Best to leave this purely to the Views to decide.
The closest to what you're asking is to do this in your current "~/Views/_ViewStart.cshtml":
#{
if(Context.Request.Path.StartsWith("/External", StringComparison.OrdinalIgnoreCase))
Layout = "~/Views/_ExternalLayout.cshtml";
else
Layout = "~/Views/_Layout.cshtml";
}
Where "~/Views/_ExternalLayout.cshtml" is your alternative layout.
Might want to check the leading "/" is correct on there, I can't remember if it is.
If you put this in the existing _ViewStart, then any view that is being rendering in response to a url starting with "/External" will use this new layout, otherwise the 'normal' one will be used.
Another approach is to use the routing table to add a route value that can be used here to make a layout decision; but I've gone for this approach to keep it simple.
You can specify which layout should be used when returning a view inside your 'ExternalController' controller action.
return View("View", "~/Views/Shared/_AnotherLayout.cshtml")

Is it possible to change a web2py view on the fly?

Can you change the view being used by web2py in the controller? Ideally I'd be interested in doing something like:
response.view = 'NewViewName'
You've got it exactly, though be sure to include the relative path to the view within the /views folder. So, if you have /views/default/other_view.html, you can do:
response.view = 'default/other_view.html'
You can also directly render any view:
def myfunc():
context = dict(...)
return response.render('default/other_view.html', context)
See here and here.

set every single form readonly without using widgets in the model

I am trying to build a template with some forms. I have a model with about 400 attributes for one entity. Now i want to make two different templates. In one Template the attributes should be listed like django form do. In the other template the attributes should be set readonly.
I don't want to create two diffent Forms for every attribute by using widgets.
cust_form = GeneralDataForm(instance=_customer, auto_id=False, label_suffix='')
I tried inserting the widget here but it doesn't work.
using this code you can make any form readonly. are you looking for something like this?
cust_form_read_only = make_form_readonly(cust_form)
def make_form_readonly(form):
for name, field in form.fields.items():
field.widget.attrs['readonly'] = True
field.widget.attrs['disabled'] = True
return form

Resources