Work around data binding bug in number input
Setting `bind:value` or `bind:valueAsNumber` for a number input seems to restrict what you can type in it. We work around this by switching to text inputs for now. We should probably switch back to number inputs if we can, though, because they let us take advantage of the browser's parsing and validation.
This commit is contained in:
		
							parent
							
								
									e0880d2ad2
								
							
						
					
					
						commit
						a46ef2c8d6
					
				
					 2 changed files with 10 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -138,22 +138,21 @@ pub fn Outline() -> View {
 | 
			
		|||
                                                    input(r#type="checkbox", bind:checked=cst.active)
 | 
			
		||||
                                                    div(class="cst-label") { (other_arg_label) }
 | 
			
		||||
                                                    input(
 | 
			
		||||
                                                        r#type="number",
 | 
			
		||||
                                                        step="0.01",
 | 
			
		||||
                                                        r#type="text",
 | 
			
		||||
                                                        bind:value=cst.rep_text,
 | 
			
		||||
                                                        on:change=move |event: Event| {
 | 
			
		||||
                                                            let target: HtmlInputElement = event.target().unwrap().unchecked_into();
 | 
			
		||||
                                                            let rep_valid = target.check_validity() && !target.value().is_empty();
 | 
			
		||||
                                                            batch(|| {
 | 
			
		||||
                                                                cst.rep_valid.set(rep_valid);
 | 
			
		||||
                                                                if rep_valid {
 | 
			
		||||
                                                            match target.value().parse::<f64>() {
 | 
			
		||||
                                                                Ok(rep) => batch(|| {
 | 
			
		||||
                                                                    cst.rep.set(rep);
 | 
			
		||||
                                                                    cst.rep_valid.set(true);
 | 
			
		||||
                                                                    console::log_2(
 | 
			
		||||
                                                                        &JsValue::from("Constraint rep parsed to"),
 | 
			
		||||
                                                                        &JsValue::from(target.value_as_number())
 | 
			
		||||
                                                                        &JsValue::from(rep)
 | 
			
		||||
                                                                    );
 | 
			
		||||
                                                                    cst.rep.set(target.value_as_number());
 | 
			
		||||
                                                                }
 | 
			
		||||
                                                            });
 | 
			
		||||
                                                                }),
 | 
			
		||||
                                                                Err(_) => cst.rep_valid.set(false)
 | 
			
		||||
                                                            };
 | 
			
		||||
                                                        }
 | 
			
		||||
                                                    )
 | 
			
		||||
                                                }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue