Saturday, November 7, 2026
HomeiOS Developmentios - State Variable From A Textfield With Enter Is Returning Null

ios – State Variable From A Textfield With Enter Is Returning Null

[ad_1]

I’ve a customized struct which comprises a Textfield, and a state variable related to the textfield. Each time I simply attempt to validate the Textfield, the state variable is null, even when there’s enter contained in the Textfield. Is there some factor that I’m lacking?

That is in my Signup class:

    //First Identify
    var first:EnhancedTextField = EnhancedTextField(hintIn:"First identify", widthIn: 
    metrics.dimension.width, heightIn:metrics.dimension.peak,typeIn:0); 

    //Shows First Identify Textfield
    first;

    //Once I name this perform, even when the Textfield comprises enter, the textual content state variable null:

     if(first.checkErrors()==true)
     {
        //There Was Some Error
        isValid=false;
     }
     else
     {
         //No Error
         isValid=true;
     }

Right here is my customized struct, which comprises the Textfield:

//  EnhancedTextField.swift
//  Lazuli Social
//
//  Created by user207789 on 12/29/21.
//

import SwiftUI


     
    
struct EnhancedTextField: View
{
    @State var trace: String;
    
    //First Identify Enter
    @State public var textual content: String = "" //THIS IS NULL, EVEN WHEN THERE IS INPUT
    
    //If First Identify Focus Is Modified
    @FocusState public var isFocused: Bool
    

    //StringDetector Class
    var detector: StringDetector
    
    
    public func checkErrors() -> Bool
    {
        if(sort==0)
        {
            let consequence = checkErrorsFirstName();
            return consequence;
        }
        else
        {
            return true;
        }
    }
    
    public func checkErrorsFirstName() -> Bool
    {
        //StrignDetector End result
       let consequence = detector.checkErrorsFirstName(first:self.textual content);
           
           //Error Textual content
           errorText=consequence.1;
           
           //Bordrer Shade
           borderColor=consequence.2;
           
           //Icon String
           iconName=consequence.3;
           
           //Icon Shade
           iconColor=consequence.4;
        
        //There Is An Validation Error
        if(consequence.0==true)
        {
            return true;
        }
        else
        {
            return false;
        }
        
            
    }
    
   
    var physique: some View
    {
        
            VStack (alignment: .middle)
            {
                
               //First Identify Enter
               TextField(trace, textual content: $textual content)
              .padding(.backside, peak*Alpha.tAlpha)
              .padding(.prime, peak*Alpha.tAlpha)
              .body(maxWidth: .infinity, alignment: .middle)
              .centered($isFocused)
              .textInputAutocapitalization(.by no means)
              .disableAutocorrection(true)
              .onChange(of:isFocused)
              {
                  newValue in
                  
                  if (newValue==false)
                  {
                      //Verify Validation Errors
                      checkErrors();
                      
                  }
                  .padding(.horizontal, width*0.10)
              
                      
                }
               

        }
    
}

Thanks,

Isaiah Thompson

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments