| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Formularium\Frontend\HTML\Renderable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Formularium\Datatype; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Formularium\Field; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Formularium\Frontend\HTML\Framework; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Formularium\Frontend\HTML\Renderable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Formularium\HTMLElement; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | class Renderable_number extends Renderable | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  |     public const STEP = 'step'; | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     use \Formularium\Frontend\HTML\RenderableViewableTrait; | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     public function editable($value, Field $f, HTMLElement $previous): HTMLElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $input = new HTMLElement('input'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         /** @var \Formularium\Datatype\Datatype_number $datatype */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $datatype = $f->getDatatype(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $extensions = $f->getExtensions(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $validators = $f->getValidators(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $input->setAttributes([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             'id' => $f->getName() . Framework::counter(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             'type' => ($extensions[static::HIDDEN] ?? false ? 'hidden' : 'number'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             'name' => $f->getName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             'class' => '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             'data-attribute' => $f->getName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |             'data-datatype' => $datatype->getName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             'data-basetype' => $datatype->getBasetype(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             'value' => $value, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             'title' => $f->getExtension(static::LABEL, '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         if (isset($extensions[static::PLACEHOLDER])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             $input->setAttribute('placeholder', $extensions[static::PLACEHOLDER]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         if ($validators[Datatype::REQUIRED] ?? false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             $input->setAttribute('required', 'required'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         foreach ([static::DISABLED, static::READONLY] as $v) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             if ($f->getExtension($v, false)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 $input->setAttribute($v, $v); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         if (array_key_exists(static::STEP, $validators)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             $input->setAttribute('step', $validators[static::STEP]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         if (isset($extensions[static::NO_AUTOCOMPLETE])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             $input->setAttribute('autocomplete', 'off'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  |         return $this->container($input, $f); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 58 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |  |