Requesting server when page load

I have an endpoint for school -> “/school”. This is a page for add school. This page has a model and this model contain cities vec. But Model default is empty. When page load, i should request “/city” and get all cities to model.cities.

But i could not done it. I thought, “load cities when click city select box” and yes, it loaded but it requested every time i clicked.

At the end, i have two choices. 1- Load cities when page load. 2- Load cities when add school form load.


school-rs ->

I would send a request to /city in init function in
Your updated init would look like this:

pub fn init(orders: &impl Orders<Msg>) -> Model {
    orders.perform_cmd(.. your request ...);

I tried this before but it did not work. I am missing something but i dont know what.>>

–> client/src/
105 | Self::School(page::school::init(&mut page::school::Msg::Load))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait seed::app::orders::Orders<page::school::Msg> is not implemented for page::school::Msg

I made changes.

–> client/src/
99 | Self::School(page::schol::init(&mut orders.proxy(page::schol::Msg::Load)))
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait std::clone::Clone is not implemented for page::school::Msg

When add Clone impl for school::Msg, it complain again for references etc.

orders.proxy expects parent’s Msg constructor - it works the same like orders.proxy in your update function. You have already almost working code in your

//page::school::update(msg, &mut model, &mut orders.proxy(Msg::School), ctx)

=> replace page::schol::Msg::Load with Msg::School

Finaly, it worked. Thank you so much.> ->

OT, just code notes / general tips:
1. => fn add => I would recommend to move short if arms at the top and use early returns / “guards”. E.g.:

fn add(model: &Model, ctx: &Context)-> Node<Msg>{
   if xxx { return div!["Giriş yapınız"] }
   if xxx { return div!["Kayıtlı kurumunuz mevcut"] }
   div![ ... ]

2. Switch page and ctx in Model in init:

    Model {
        page: Page::init(url.clone(), orders),
        ctx: Context {
            base_url: url.to_base_url(),


    Model {
        ctx: Context {
            base_url: url.to_base_url(),
        page: Page::init(url, orders),

Notice removed .clone() at the url.

Yes, i mixed a lot of things for this problem and its very bad :slight_smile: I will change them soon, thank you again.