@@ -12,8 +12,9 @@ use crate::{
1212 error,
1313 form_footer:: FormFooter ,
1414 layout:: { ElementLayout , ElementLayoutStyle , Elemental } ,
15- prelude:: i18n,
15+ prelude:: { i18n, CallbackFn } ,
1616 result:: Result ,
17+ error:: Error ,
1718//view::Layout,
1819//document,
1920//module::ModuleInterface
@@ -188,6 +189,7 @@ pub struct FormStages {
188189pub stages : Arc < Mutex < Vec < Arc < dyn FormStage > > > > ,
189190pub data : Arc < Mutex < FormData > > ,
190191pub title : Arc < Mutex < String > > ,
192+ error_cb : Arc < Mutex < Option < CallbackFn < Error > > > > ,
191193}
192194
193195unsafe impl Send for FormStages { }
@@ -203,14 +205,15 @@ impl FormStages {
203205let layout =ElementLayout :: new ( parent_layout, layout_style, attributes) ?;
204206let title = attributes
205207. get ( "title" )
206- . unwrap_or ( & "Step [INDEX]" . to_string ( ) )
208+ . unwrap_or ( & "Step [INDEX]/[STEPS] " . to_string ( ) )
207209. clone ( ) ;
208210let layout =FormStages {
209211 layout,
210212title : Arc :: new ( Mutex :: new ( title) ) ,
211213index : Arc :: new ( Mutex :: new ( 0 ) ) ,
212214stages : Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ,
213215data : Arc :: new ( Mutex :: new ( FormData :: new ( None ) ) ) ,
216+ error_cb : Arc :: new ( Mutex :: new ( None ) ) ,
214217} ;
215218
216219Ok ( layout)
@@ -360,11 +363,24 @@ impl FormStages {
360363if let Some ( el) =self . layout . element ( ) . query_selector ( ".layout-title" ) ?{
361364let title = title
362365. as_ref ( )
363- . replace ( "[INDEX]" , & format ! ( "{}" , self . index( ) ? +1 ) ) ;
366+ . replace ( "[INDEX]" , & format ! ( "{}" , self . index( ) ? +1 ) )
367+ . replace ( "[STEPS]" , & format ! ( "{}" , self . len( ) ?) ) ;
364368 el. set_inner_html ( & title)
365369}
366370Ok ( ( ) )
367371}
372+
373+ pub fn on_error ( & self , callback : CallbackFn < Error > ) {
374+ * self . error_cb . lock ( ) . unwrap ( ) =Some ( callback) ;
375+ }
376+
377+ pub fn show_error ( & self , error : Error ) ->Result < ( ) > {
378+ if let Some ( cb) =self . error_cb . lock ( ) ?. as_mut ( ) {
379+ cb ( error) ?;
380+ }
381+
382+ Ok ( ( ) )
383+ }
368384}
369385
370386impl Elemental for FormStages {